You are on page 1of 28

Multiple Condition

(and RadioButton +
CheckBox)
Meeting #4

1
MULTIPLE CONDITION
• It is very common to have more than 1 condition
before an action can be performed

• For example:
If I was born in December and I spent money
more than 100000, I will get special
prize

• Actually there are 2 conditions that must be fulfilled


before an action “get special prize” can be performed.
What are they?
2
MULTIPLE CONDITION
• If you have more than one condition, you have
to combine it with a logical operator.
• The logical operator in the previous example is
the word “and”
• There are two logical operator that commonly
used in C#. They are:
 && : to represent the word “and”
 || : to represent the word “or” (the keyboard
button
for character “|” can be found above the Enter)
3
MULTIPLE CONDITION

4
CHARACTERISTIC OF AND ||
• &&: The combined conditions are said “satisfied” or true if every
condition is satisfied (true). [otherwise it is false]
• Example:
If (I was born in December and I spent money
more than 100000), I will get special prize

• The combined condition is satisfied/true (so you will do the


action to get special prize) if the facts show that
 You were born in December – 1st condition is satisfied, and
 You spent money more than 10000 – 2nd condition is satisfied

5
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
otherwise
You cannot open a bank account

• The combined condition is satisfied/true (so you will do the action to open
a bank account) if the facts show that at least one of this condition is
satisfied:
 You have a driving license – 1st condition is satisfied, or
 You have an identity card (KTP) – 2nd condition is satisfied. 6
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 don’t give bracket, the combined condition
with && will be processed first than the one with ||.

7
HIERARCHY OF && AND ||:
EXAMPLE 1
If (My friend treat me or I am hungry and
I have money)
I will buy some food
Else
I will not by any food
• Will the combined condition gives value true (means: you buy food) if
the facts show that:
1. Friend treat: No; Hungry: No; Have Money: No
2. Friend treat: Yes; Hungry: No; Have Money: No
3. Friend treat: Yes; Hungry: Yes; Have Money: No
4. Friend treat: Yes; Hungry: No; Have Money: Yes
5. Friend treat: Yes; Hungry: Yes; Have Money: Yes

8
CHARACTERISTIC OF && AND ||:
EXAMPLE 2
If ( (My friend treat me or I am hungry)
and I have money)
I will buy some food
Else
I will not by any food
• Will the combined condition gives value true (means: you buy food) if
the facts show that:
1. Friend treat: No; Hungry: No; Have Money: No
2. Friend treat: Yes; Hungry: No; Have Money: No
3. Friend treat: Yes; Hungry: Yes; Have Money: No
4. Friend treat: Yes; Hungry: No; Have Money: Yes
5. Friend treat: Yes; Hungry: Yes; Have Money: Yes
• Which example represent the condition in your real life?
9
COMMON USE OF && IN
PROGRAMMING
• The operator && is usually used to check if a number is inside a certain
range of number or not.
• For example: human will fill comfortable (not too cold, not too hot), in a
range of temperature of 200C – 260C. Defined if a certain temperature will
make the person comfortable/not.

if (temperature >= 20 && temperature <= 26)


{ result = “comfortable”; }
else
{ result = “not comfortable”; }
10
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.

if (temperature < 20 || temperature > 26)


{ result = “not comfortable”; }
else
{ result = “comfortable”; }
11
Example
• You were asked to write a program for starbucks
coffee, to check if a certain customer get a
Rp.50.000 voucher or not.
• A customer will get a voucher if the customer buy
coffee and cakes, and the total price of the order is
greater than or equal to 200.000
• Greet the customer in the receipt with his/her title
before you write his/her name. Use “Mr.” for male
customer, and “Miss/Mrs/Ms.” for female customer.
You need to enter the customer gender and name
into the system.
12
Example
• Input:
– Customer gender
– Customer name
– Information about if the customer buy coffee
– Information about if the customer buy cakes
– Total price of order
• Output (the output in red should be the same as data in
the input. Note: the listbox must be cleared )
– Receipt to customer, that is shown in list box. Example:
Mr. Budi
Your total order is: 250000
You get a free Rp.50,000 voucher
13
Example
• Another example of output (the output in red should
be the same as data in the input)
– Receipt to customer, that is shown in list box. Example:
Miss/Mrs/Ms. Cynthia
Your total order is: 170000
Enjoy your day.

14
Example User Interface (UI)

15
The
code

16
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.

17
Radio Button
• Check the value inside property Checked
if (radioButtonMale.Checked == true)
{
:
}
• Or you can make it shorter by removing “ == true” (C# will assume that
you want to check with true)
if (radioButtonMale.Checked)
{
:
}
• Set/Change the value inside property Checked with true or false.
radioButtonMale.Checked = true;

18
Check Box
• Check box will toggle individually. Therefore you
don’t 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.

19
CheckBox – the same as
RadioButton
• Check the value inside property Checked
if (checkBoxCoffee.Checked == true)
{
:
}
• Or you can make it shorter by removing “ == true” (C# will assume that
you want to check with true)
if (checkBoxCoffee.Checked)
{
:
}
• Set/Change the value inside property Checked with true or false.
checkBoxCoffee.Checked = true;

20
Exercise
project name: yourName-CekKelulusan

• Create an application that can check if an IF 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:
• Algoritma dan Pemrograman
• Kerja Praktek
• Tugas Akhir
• Mention in the output, what is the major program taken by the student.
It can be one of these:
– Informatika - Multimedia
– Sistem Informasi - IT-DD

21
Example of User Interface
(UI)

22
Exercise – Output version 1
• Possibility 1:
Nama mahasiswa: Budi Hartanto
Program studi/kekhususan: Informatika
Total SKS yang telah diambil: 145
Semua MK wajib telah diambil dan lulus.
Mahasiswa dapat diwisuda.
• Possibility 2:
Nama mahasiswa: Cyndi Harahap
Program studi/kekhususan: Sistem Informasi
Total SKS yang telah diambil: 145
Belum semua MK wajib diambil/ masih belum lulus.
Mahasiswa belum dapat diwisuda.

23
Exercise – Output version 2
Comment your previous code, and add new code to produce
output below

• Possibility 1:
Nama mahasiswa: Budi Hartanto
Program studi/kekhususan: Informatika
Total SKS yang telah diambil: 145
Matakuliah wajib yang harus diambil dan lulus:
* Algoritma dan Pemrograman: LULUS
* Kerja Praktek: LULUS
* Tugas Akhir: LULUS
Semua MK wajib telah diambil dan lulus.
Mahasiswa dapat diwisuda.

24
Exercise – Output version 2
Comment your previous code, and add new code to produce
output below

• Possibility 2:
Nama mahasiswa: Cyndi Harahap
Program studi/kekhususan: Sistem Informasi
Total SKS yang telah diambil: 145
* Algoritma dan Pemrograman: BELUM LULUS
* Kerja Praktek: BELUM LULUS
* Tugas Akhir: LULUS
Belum semua MK wajib diambil / masih belum lulus.
Mahasiswa belum dapat diwisuda.

25
UPLOAD YOUR WORK
• Make a folder named: allExercises_KP_YourName
(note: NO SPACE in the filename. Example: allExercises_D_Budi)
• Put the projects that you’ve done to that folder (your teacher will tell you,
which one)
• Zip the folder allExercises_KP_YourName. How?
– Right click the folder
– Select: Send to Compressed (Zipped) folder
• Upload the zip file to the uls, in Topic 3/Topic 4
(Then find the correct “kelas parallel/KP” – KP A, B, C, etc)
• MAXIMAL SIZE: 10 Mbytes
• Notes: if your files are too big, DELETE all folder debug/release

26
Latihan
Rumah makan “Leza” memberikan penawaran
special bagi para wanita yang makan di rumah
makan ini pada tanggal 22. Penawaran yang
diberikan adalah diskon sebesar 40% khusus
makanan saja apabila total tagihan di atas Rp
250.000,-, selain itu diskon makanan sebesar 10%.
Penawaran diskon hanya diberikan untuk wanita saja.
Buatlah program untuk membantu menghitung total
yang harus dibayarkan oleh seorang pelanggan yang
makan di rumah makan ini. Contoh tampilan dan
output dapat dilihat pada gambar di bawah ini.
27
28

You might also like