Exercise Ready To PSPM, Matriculation (Science Computer)
Exercise Ready To PSPM, Matriculation (Science Computer)
Exercise Ready To PSPM, Matriculation (Science Computer)
[3 marks]
Weight
Input
Calculate charge
Process
Charge
Output
Start
Enter weight
If weight <=1
charge=10+5
else
charge=(weight-1)*0.01+10
endif
Print charge
End
Start
Y=5
while (Y >1)
Y=Y-2
print Y
repeat checking while
end while
End
1
i. How many times the loop will be executed before it terminates?
[2 marks]
____________________________0______________________________________
i. 16 / 4 * 3 -1
[1 mark]
_____11_____________________________________________________________
ii. 16 / 4 * (3 -1)
[1 mark]
________8__________________________________________________________
iii. (18 / 9 + 4 * 3)
[1 mark]
_____14_____________________________________________________________
(b) Identify an output for the given expression. An output is 0 when the expression is FALSE and output is 1
when an expression is TRUE.
Given, A = 6, B = 2, C = 4
[2 marks]
Expression Output
20 / C > A + B / 2 0
2
A % B * C <= 2 1
[3 marks]
______________Area=3.142*r*r____________________________________________________
7. (a) Study the program segment below and answer all the questions
if (celc<=0)
System.out.print(“Ice\n”);
if (celc<=100)
System.out.print (“Water\n”);
else
System.out.print (“Steam\n”);
System.out.print(“End\n”);
i. 110
[2 marks]
___________Steam_______________________________________________________
ii. -6
[3 marks]
________Ice__________________________________________________________
(b) Write complete JAVA if statement for the following situation. Use valid and suitable variables names.
i. Code number for petrol RON95 is 1, RON97 is 2. If Joe buy petrol RON 95, display “Cheaper than
RON 97”. If not, display “Expensive than RON 95” .
[3 marks]
import java.uti.Scanner;
public class RON{
public static void main(String [] args){
Scanner kim=new Scanner(System.in);
System.out.println(“Enter code: ”);
int code=kim.nextInt();
3
if(code=1){
System.out.println(“Cheaper than RON 97”);}
else if(code=2){
System.out.println(“Expensive than RON 95”);}
else{
System.out.println(“Invalid code”);}
}
}
ii. Calculation of two (2) numbers(x and y) are based on menu provided as follows.
Press „*‟, multiply two(2) numbers and store as Mult. If press „+‟, add two(2) numbers and
store as Add. Otherwise, print “invalid operation” message.
[5 marks]
(c) The following if code statement will print suitable name based on month entered. If value of month is 8,fill
up the blank space with suitable name of month from January to December in the most appropriate cout statement.
if (month / 2 == 3)
System.out.print( “_________________”);
else if(month / 3 == 5)
System.out.print( “_________________”);
else if(month / 4 == 2)
System.out.print( “ _________________”);
[6 marks]
4
Example :
Output 1 :
Enter number : 8
Positive & Even
Output 2 :
Enter number : -5
Number cannot be identified
Output 3 :
Enter number : 39
Positive & Odd
import java.util.Scanner;
public class Number{
public static void main(String [] args){
Scanner kim=new Scanner(System.in);
System.out.print(“Enter number: ”);
int num=kim.nextInt();
if(num%2==0){
System.out.println(“Positive & Even”);}
else if(num%!=0){
System.out.println(“Positive & Odd”);}
else if(num<0){
System.out.println(“Number cannot be identified”);}
}
}
(b) At Kolej Bangsa Johor (KBJ) students pay RM250 per credit, with a per-semester tuition fee of RM3350
(compulsory). Additionally, a student must take at least 12 credits to be considered full time, and no student may take
more than 20 credits. Write a program that inputs the student‟s number of credits, then outputs that student‟s status
whether part time (PT) or full time (FT), and total tuition fee. Print appropriate error
messages if the credit entered is greater than 20. (Use the given identifiers / variables).
5
[11 marks]
import java.util.Scanner;
public class KBJ{
public static void main(String [] args){
Scanner kim=new Scanner(System.in);
Int tufe;
System.out.println(“Enter your number of credits: ”);
Int cre=kim.nextInt();
if(cre<12){
tufe=3350+(cre*250);
System.out.println(“Part time (PT)”);
System.out.println(“Total tuition fee is ”+tufe);}
else if(12<=cre<=20){
tufe=3350+(cre*250);
System.out.println(“Full time (FT)”);
System.out.println(“Total tuition fee is ”tufe);}
else
System.out.println(“Your number of credits iover the limit”);
}
}
6
7