0% found this document useful (0 votes)
48 views

List Box and Exercises: If Ubaya (Infor+Sib+Mm+Itdd)

The document provides instructions and examples for two coding exercises: 1) a restaurant bill calculator that calculates total bill amount including discount, service charge, tax; and 2) a currency calculator that converts amounts between currencies. It reviews data types in C# and demonstrates how to view variable values at different points in code using breakpoints. Formulas and user interfaces are provided as guidance for the exercises.

Uploaded by

Bagus
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

List Box and Exercises: If Ubaya (Infor+Sib+Mm+Itdd)

The document provides instructions and examples for two coding exercises: 1) a restaurant bill calculator that calculates total bill amount including discount, service charge, tax; and 2) a currency calculator that converts amounts between currencies. It reviews data types in C# and demonstrates how to view variable values at different points in code using breakpoints. Formulas and user interfaces are provided as guidance for the exercises.

Uploaded by

Bagus
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

LIST BOX AND EXERCISES

IF UBAYA (Infor+SIB+MM+ITDD)
REVIEW OF DATA TYPES
• Previously you’ve learnt three data types in C#. They are:
 s...... to represents Text
 i...... to represents whole number, and
 d..... to represents floating point or fractional number
• When two data types that are involved in the expression or
assignment statement are not the same, we have to eq.......... the
data types
• C# can do this automatically to convert:
 i.... : To double,
2

 int or double: To s..... if we have another string and “+” operator


REVIEW OF DATA TYPES
• Other than that, we have to convert manually by a certain method:
 converting (int or double) to string: use .To......(); method
 converting double to int: use typ........... by writing (int) in front of the
number/the variable/the math expression
 converting string to (int or double): use .Pa.... (); method

• Just to remind you:


 an integer division will always give you an in........ result
 a remainder of a division can be obtained by using the .... operator that is
called mod......... 3
THE CONTENT OF THE VARIABLE
• Previously we have created a simple calculator. Let’s see the content of the Text
Property and the variable in each step of the process
• You can see the content of the variable by:
 click the variable that you want to see its content
 press F9 to give a break point
 run your program as usual by clicking the green arrow or by pressing F5. Your
program will stop at the break point when it passes that line of code.
 Press F10 to execute the code in that line and you can see the content of the
variable in the Auto or Local or Watch windows (if you can’t see the window,
select: Debug>Windows>Auto/Local/Wach). Keep pressing F10 if you want to
see the content of the variable in the next line.
 If you don’t need the break point anymore, press F9 again in the location of the
4

break point. Run your program normally using F5.


THE CONTENT OF THE VARIABLE
• For example, the text boxes in our
Simple Calculator have been
filled by user with 20 and 30
respectively.
• And Add button is clicked
• Let’s see the content of each Text
property and the variable in the
next slides.

5
BEFORE EXECUTING LINE FIRSTNUM
• The yellow line shows that the
code HAS NOT BEEN processed
(you can press F10 to process it)
• In this case, we can see that
before that line is processed,
the content of:
• The variable firstNum is still 0
• The Text property of
textBoxFirstNumber contains
“20” ( not 20 ! ) 6
BEFORE EXECUTING LINE SECONDNUM
• Now after executing firstNum
line, we can see that
• The variable firstNum now contains
20 (int.Parse changes “20” to 20)
• The Text property of
textBoxFirstNumber still contains
“20”

• The variable secondNum is still 0,


• The Text property of
textBoxSecondNumber contains
7 “30”

What is the content of secondNum and textBoxSecondNumber.Text after that line is executed?
THE CONTENT OF VARIABLES
• What is the content of the
following variables and the
Text property, when the
process has come to the end
of the program?
• firstNum
• secondNum
• resultPlus
• textBoxFirstNumber.Text
• textBoxSecondNumber.Text
8

• labelShowResult.Text
EXERCISES

9
RESTAURANT BILL CALCULATOR
Project Name: Your First Name – BillCalculator

• Create a restaurant bill calculator application to find the amount


of charges that you must pay in a certain restaurant.
• Your calculator should ask the user about:
The initial total bill for the food and drink
The percentange of discount for that bill (default value: 30%)
The percentage of service charge (default value: 5%)
The percentage of tax (default value: 10%)
• Your calculator should display:
The amount of discount that is received by the user
The amount of service charge that must be paid
The amount of tax that must be paid 10

The total bill that the user must pay


RESTAURANT BILL CALCULATOR
THE FORMULA
• You can see the following formula in the last slide.
• If possible, try to think the formula yourself.
• But, if you don’t know, you are welcomed to see the following
formula in there.
• The last slide will contain the formula to calculate:
• The amount of the Discount
• The amount of the Service charge
• The amount of the Tax
• The Total Bill that must be paid
• Check the correctness of your formula, by comparing your numbers to
11

the example input and output in the user interface in slide #13
USER INTERFACE AND THE REQUIREMENTS
• User Interface at Design time • When it is run at the first time

To “right align” the text in TextBox and Label:


12
• For TextBoxes: set property TextAlign to Right
• For Labels: set property TextAlign to MiddleRight
USER INTERFACE AND THE REQUIREMENTS
• When the button Calculate is Clicked and the
user has enter the data into the text boxes
• When the button Clear is Clicked

13
EXERCISE #2
CURRENCY CALCULATOR

14
CURRENCY CALCULATOR
Project Name: YourFirstName – Currency Calculator

• Create a currency calculator to find the amount of money in other


currency.
• Your calculator should let the user to enter:
The currencies involved in the excange (initially they are set to: USD and IDR)
The exchange rate
The amount of money to be exchanged from the source currency
• Your calculator should display:
The amount of money in the destination currency
The history of the conversion that has been made (autoscroll to the last
conversion) 15
USER INTERFACE AT DESIGN TIME
Set property TabStop to False, so the cursor
will not go there when you press Tab in your
keyboard. You can go there by click it.

These are Group Boxes

This is a List Box


(Set the Tab Stop to False as well)

16
WHEN THE USER CHANGES THE CURRENCY

When the user changes the


currency in these text boxes
also change the corresponding
currency in these labels

You can do this by writing code in the


TextChanged event handler of the Text
Box.

(in this case, just set the Text property


of the label to be the same as Text
property of the text box) 17
WHEN THE USER CLICKS CALCULATE BUTTON

The user enters the Rate and the


amount of money to be changed

When Calculate button is clicked:


• Calculate the amount of money in the destination
currency and display it in the label
• Display the history of the conversion. Write the
following code:
General Format:
listBoxHistory.Items.Add(stringToBeDisplayed);
18
Example:
listBoxHistory.Items.Add(“Currency...”+textBoxFromCurrency.Text);
AUTOSCROLL IN A LISTBOX

When Calculate button is clicked several times:


• The list box will do AUTO SCROLL and display
the last currency conversion in the bottom
• To do autoscroll in a list box, type the
following code:
listBoxHistory.TopIndex = listBoxHistory.Items.Count – 1;

19
WHEN THE USER CLICKS CLEAR ALL BUTTON

• To set the cursor to the textBoxRate, write


textBoxRate the following code (in the buttonClearAll) :
textBoxRate.Focus();

• To clear all items in the listBox, write the


following code:
listBoxHistory.Items.Clear();

20
RESTAURANT BILL CALCULATOR
THE FORMULA

• The amount of the Discount


disc = percentDisc/100.0 * initialBill
• The amount of the Service charge
service = percentService/100.0 * (initialBill – disc)
• The amount of the Tax
tax = percentTax/100.0 * (initialBill – disc + service)
• The Total Bill that must be paid
totalBill = initialBill – disc + service + tax

Notes: it is assumed that all variables with the names preceded by the word21
“percent” contain a percentage number that have not been divided by 100
(for example it contains 20 to represent 20%)

You might also like