Sie sind auf Seite 1von 7

(b) Courier Company will charge automatically RM 10.

00 for any items that customer want


to deliver. An extra charge will be imposed depend on it‟s weight based on following table. Calculate
and display the charge.

Weight less than or equal 1kg Weight more than 1 kg


Additional RM 5 Additional RM 0.01 per gram
i. Identify the input, process and output.

[3 marks]

Weight
Input

Calculate charge
Process

Charge
Output

ii. Write a pseudocode for the above situation


[5 marks]

Start
Enter weight
If weight <=1
charge=10+5
else
charge=(weight-1)*0.01+10
endif
Print charge
End

2. (a) Based on pseudo code below, answer all the questions

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______________________________________

ii. What is the current value of Y before repetition stop ?


[2 marks]
____________________________3______________________________________

iii. Convert pseudo code into corresponding flowchart


[7 marks]

6. (a) Give the value of the following arithmetic expression.

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

(c) Convert the following algebraic expression into expressions.


i.
[3 marks]
__________________Q=P(1+r/n)________________________________________________
ii.

[3 marks]
______________Area=3.142*r*r____________________________________________________

7. (a) Study the program segment below and answer all the questions

System.out.println(“ Enter Celcius “); celc=sc.nextDouble();

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”);

Provide the output for the following input.

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( “ _________________”);

8. Write a complete JAVA program to solve the following problems:


(a)
User are allows to enter any integer . Then, the program will check and display the suitable output
whether it is “Positive & Even” or “Positive & Odd”. If user enter any
number less than zero, then display “Number cannot be identified”.

[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).

Part Time RM3350 < 12 credits One credit


Full Time (compulsory tuition fee) 12 ≤ credits ≤ 20 = RM250

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

Das könnte Ihnen auch gefallen