Академический Документы
Профессиональный Документы
Культура Документы
(+RadioButton +CheckBox)
IF UBAYA
(Infor+SI+MM+ITDD) 1
MULTIPLE CONDITION
It is very common to have more than 1 condition
before an action can be performed
Remember the previous example:
If (I am hungry and I have money)
I will buy some food
Else
I will not buy any food
3
CHARACTERISTIC OF && AND ||
&&: The combined conditions are said satisfied or true if all
conditions are satisfied (true). [otherwise it is false]
Example:
If (I am hungry and I have money)
I will buy some food
Else
I will not by any food
4
CHARACTERISTIC OF && AND ||
||: The combined conditions are said satisfied or true if
at least one condition is satisfied (true). [otherwise it is false]
Example:
If (You have a driving license or you have an
identity card)
You can open a bank account
Else
You cannot open a bank account
The combined condition is satisfied/true (so you will open a
bank account) if the facts show that at least one of the
conditions is satisfied:
You have a driving license [1st condition is satisfied], or
You have an identity card (KTP) [2nd condition is satisfied].
5
CHARACTERISTIC OF && AND ||
Hierarchy: && has higher operation hierarchy than ||.
This is similar to the hierarchy of multiplication and
addition (i.e. multiplication has higher hierarchy than
addition)
In expression: 1 + 2 * 3, you will do multiplication
first then followed by the addition
So, if you dont give bracket, the combined condition
with && will be processed first than the one with ||.
6
HIERARCHY OF && AND ||: EXAMPLE 1
If (My friend treat me or I am hungry
and I like the food provided)
I will eat the food provided
Else
I will not eat the food provided
string result = ;
if (temperature>=20 && temperature<=26)
result = comfortable;
else
result = not comfortable;
9
COMMON USE OF || IN PROGRAMMING
The operator || is usually used to check if a number is
outside a certain range of number or not.
For example: the same example in the previous slide, can be
written as: human will not feel comfortable if the
temperature is below 200C or above 260C.
string result=;
if (temperature<20 || temperature>26)
result = not comfortable;
else
result = comfortable;
10
Example
You were asked to write a program for Starbucks
coffee, to check if a certain customer get a
Rp.20.000 voucher or not.
A customer will get a voucher if the customer
buy coffee and cakes, or the total price of the
order is greater than or equal to 200.000
11
Example User Interface (UI)
12
Example
Input:
Customer name
Customer gender
Information if the customer buy coffee/not
Information if the customer buy cakes/not
Total price of order (note: to simplify the example, in this
case we input the total price of the order. Usually, this
value is calculated by the program)
15
Example 3 of input - output
Input:
Customer name: Jennifer
Customer gender: Female
Check box order coffee is checked? Yes
Check box order cakes is checked? No
Total price of order: 70 000
Display the following text in the List Box:
Miss/Mrs/Ms. Jennifer
Your total order is: 70000
You order coffee
Enjoy your day
16
The Code
17
Radio Button
Place the radio buttons into a container
(GroupBox or Panel control) to make them toggle
automatically when it is selected by the user.
Check the value inside property Checked, to see
if a radio button is selected or not. If it is selected,
property Checked will contain value true,
otherwise it is false.
The default characteristic of radio button: one
radio button must be selected when the program
starts. You can do this in Design View or by the
program.
18
Radio Button
Check the value inside property Checked
// version 1
if (radioButtonMale.Checked == true)
{
:
Can be read as: Is the content of
}
radioButtonMale.Checked is equal to true?
20
Check Box
Check box will toggle individually. Therefore you
dont need to place them into a container to make
it works.
Check the value inside property Checked, to see
if a check box is selected or not. If it is selected,
property Checked will contain value true,
otherwise it is false.
There is no default characteristic of check box.
You can set or clear any check box that you like.
21
Check the value inside a check box
Check the value inside property Checked
if (checkBoxCoffee.Checked == true)
{
:
}
22
Change the check on a check box
23
Exercise
project name: yourName-GraduatesChecker
Create an application that can check if an a
certain student can be graduated or not.
A student can be graduated if:
The student already took at least 144 credits
The student already passed the following course:
Algorithm and Programming
Internship
Final Project
Display a certain message in the list box, such as
shown by the examples in the next slides
24
Example of User Interface (UI)
25
Example 1 of Input-Output
Example of inputs:
Name: Budi Hartanto
Study Program: Informatics Engineering
Total Credits Taken: 145
Compulsory courses taken: ALL are checked
28
Upload your works in uls
29