Professional Documents
Culture Documents
(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
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
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.
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
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