Professional Documents
Culture Documents
(MULTIPLE SELECTION) –
more than 2 choices
START
INPUT
IF condition1
statement1
ELSE IF condition2
statement2
.
.
.
ELSE IF condition n
statement n
ELSE
last statement
END IF
STOP
1. Write a program that will accept a number. Display “Negative number” if
the number is less than 0. If the number is greater than 0, display “Positive
number”. Otherwise, display “The number is 0”.
number < 0 – “Negative number”
number > 0 – “Positive number”
“The number is 0”
IPO :
INPUT PROCESS OUTPUT
number determine number less than 0 or “Negative number” OR
not to identify positive, negative “Positive number” OR
or zero “The number is 0”
2. Suppose that temperature is an int variable representing the
temperature of an oven. Write a program that output the phrases
below based on temperature input from the user
≤ 200
Value of temperature Phrase to print
Not over 200 IF Too cold to cook
≤ 350 > 200 , ≤ 350
Over 200 but not over 350 ELSE IF Oven is preheating
≤ 425 > 350 , ≤ 425
Over 350 but not over 425 ELSE IF Put in the apple pie
≤ 500 > 425 , ≤ 500 Over 425 but not over 500 ELSE IF Time to cook pizza
>500 Over 500 ELSE Call the fire department
IPO :
INPUT PROCESS OUTPUT
temperature determine “Too cold to cook” OR
temperature less than “Oven is preheating” OR
or equal to 200 or not “Put in the apple pie” OR
to identify the phrases
“Time to cook pizza” OR
“Call the fire department”
FLOWCHART (HOMEWORK)
3. Write a program that will display the amount of commission that
a worker will get based on the sales achieved.
Sales Commission Rate
< 10000
Less than RM 10,000 IF 10% 0.1
≤ 15000 ≥ 10000 - ≤ 15000
RM 10,000 – RM 15,000 ELSE IF 15% 0.15
>15000 Over RM 15,000 ELSE 20% 0.2
IPO :
INPUT sales
PROCESS determine sales less than 10000 or not then calculate amount
of commission based on sales
OUTPUT amount of commission
Pseudocode :
START
READ sales
IF sales < 10000
amount of commission = sales x 0.1
ELSE IF sales ≤ 15000
amount of commission = sales x 0.15
ELSE
amount of commission = sales x 0.2
END IF
DISPLAY amount of commission
STOP
FLOWCHART (HOMEWORK)
4. A courier company, GoFast want to use a computer program to determine
payment of their mileage claims. Their programmer ask for your help to
write the program. The payment is calculated using this table.
KM Cents per KM
First 500 50
Next 200 40
Each extra km 30
Example :
a. If the travel took 100 km, they should pay RM50.00
b. If the travel took 600 km, they should pay RM290.00 (that is 250 + 40)
c. If the travel took 800 km, they should pay RM360.00 (that is 250 + 80 + 30)
Coding 1 :
System.out.print(“KMPk”);
System.out.print(“Gopeng”);
Output :
KMPkGopeng
Coding 2 :
System.out.println(“KMPk”);
System.out.print(“Gopeng”);
Output :
KMPk
Gopeng
Coding 3 :
Output :
18age
Coding 4 :
String location = “Gopeng”;
System.out.print(“location”);
System.out.print(location);
Output :
locationGopeng
Coding 5 :
String location = “Gopeng”;
System.out.print(“location ”);
System.out.print(location);
Output :
location Gopeng
Coding 6 :
int age = 18;
System.out.print(“My age is “+age);
Output :
My age is 18
User input : KMPk Gopeng
3. Declare and create a variable name flag and assign the value ‘true’
to it
boolean flag = true;
4. Declare a variable name grade
char grade;