0% found this document useful (0 votes)
764 views8 pages

Answer Scheme KMPP SC025

This document contains an answer scheme for a programming exam. It includes the following: 1. Steps to problem solving and identifying control structures based on given statements. 2. Writing pseudocode to calculate incentives for employees based on work experience and monthly sales. 3. Creating a flowchart for a program that calculates totals for families with more than 3 children.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
764 views8 pages

Answer Scheme KMPP SC025

This document contains an answer scheme for a programming exam. It includes the following: 1. Steps to problem solving and identifying control structures based on given statements. 2. Writing pseudocode to calculate incentives for employees based on work experience and monthly sales. 3. Creating a flowchart for a program that calculates totals for families with more than 3 children.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

ANSWER SCHEME SC025

2021/2022 SESSION

1. (a) Identify the steps in problem solving based on the given statements.
[4 marks]

Statement Step in Problem Solving

Change the value of a variable a few Testing ----J1


(i)
times to ensure that the formula is correct.

(ii) Make a simple explanation on the codes. Documentation --- J1

Programmers determine type of control Problem analysis --- J1


(iii)
structure to identify process.

Write a Pseudocode to find the largest Design a solution--- J1


(iv) number from three different numbers
entered by user.

(b) MYShop gives RM30 voucher to customers for every RM300 purchase.
Calculate the value of vouchers Datin Halimah will get if she goes
shopping at MYShop on the first day of May. State the input, process
and output involved in this transaction.
[3 marks]

Input purchase – J½

Process To determine voucher based on the purchase --- J2

Output voucher --- J½

(c) Get two numbers from the user and display the larger number.
[4 marks]

Input num1, num2 – J1

Process To determine the larger number between two numbers--- J2

Output larger – J1

2 (a) Identify the control structure based on the given description.

(i) "Continuous checking of user data enters until an acceptable


entry is made, such as a valid password; counting and
accumulating running totals; and recurrent acceptance of input

1
data and recalculation of output values that only end when a
designated value is entered"
[1 mark]
Repetition/Looping/Iteration ----------------J1

(ii) Conditional statements are features of a programming


language, which perform different computations or actions
depending on whether a programmer-specified Boolean
condition evaluates to true or false
[1 mark]
Selection ------------ J1

(b) SukaHati Company offers an incentive for Hari Raya Aidilfitri to the staff
as follows:

Work Experience Monthly Sales Incentive

5 years and above RM50 000 and above RM10 000

Less than RM50 000 RM5 000

Others Not specified RM2 000

Write a pseudocode to calculate the incentives that will be


received by the employee.
[6 marks]
START
Read WorkEx, MonthlySales --------- J½, J½
if (WorkEx = 5 ) ----------J1
if (MonthlySales >= 50000) ----------J1
Incentive = 10000 ----- J1
else
Incentive = 5000 -----J1
end if
else
Incentive = 2000 -------J1
endif
STOP

(c) Draw a flowchart for a program that asks the user for the number of
children in each family. If the number of children is larger than three,
the computer will calculate the total of a large family. When the user
enters -1, the program will stop and display the total of the large family
with the message "Family needs MPV."
[6 marks]

2


J ½J ½ J½



J½ J½

3 (a) Write Java statements to execute the following tasks:

(i) Declare a constant named PRICE, where the value is 40.00.


[2 marks]
final double PRICE=40.00; or
final float PRICE = 40.00;

(ii) Calculate the area of the triangle.


area = ½bh
[2 marks]
double area = (b * h)/2; or area = 0.5 * b * h; or
area=1.0/2 * b * h; or area=1/2.0 * b * h; or area=(1
/2)*b*h;

(b) Identify the most suitable primitive data types for the following
situations.

(i) To store the choice to print the receipt, whether Y (for Yes) or N
(for No).
[1 mark]
char -----------J1

(ii) To store the value of an average temperature in a week.


[1 mark]

double/float ---------- J1

3
(iii) To perform logical operations, most commonly to determine
whether some condition is false.
[1 mark]
boolean -----------J1

(iv) To store the COVID-19 cases per 100 people in last 6 months in
Malaysia
[1 mark]
int -------------- J1

(c) Construct the following expressions in correct Java syntax.

(i) x 3 – 6yz
[1 mark]
(x * x * x) – 6 * y * z ; or

Math.pow(x, 3) – 6 * y * z;

1+2𝑎 4 (𝑏+𝑐)(5−𝑑)
(ii) +
3 𝑓
[1 mark]
((1 + 2 *a)/3) + (4 * (b + c)* (5 – d))/f;

(d) Solve the following expression by analysing the precedence of the


respective operator.

(i) ( 5.0 * (98.4 - 32.0) ) / 9.0


[1 mark]
36.89

(ii) 3 + 6 / 2 * 3 - 1 + 2.0
[1 mark]
13.0

(e) What is the output of the following code?

(i) t = 10;
if(t < 15)
System.out.print("AAA");
System.out.print("BBB");
[1 mark]
AAABBB

(ii) b = 1;
while(b > 8)
{
System.out.print(b + " ");

4
b = b + 2;
}
[1 mark]
No output

(f) Suppose target is a variable of type int. Write a program segment that
displays “Excellent!” if the value of the variable target is greater than
10, otherwise display “Try again! “. Assume sc as a scanner object.
[3 marks]

int target = sc.nextInt( ); ---------- J1


if (target > 10) ---------- J1
System.out.print(“Excellent!”); ---------J½
else
System.out.print(“Try again!”); ---------J½

(g) Convert the for loop to a while loop without changing the output.
Assume all variables have been declared.
[3 marks]
int R;
for (int q=15; q >=11; q++)
R = q+ 2
System.out.println(R);

int q=15, R;------------ J1


while ( q >= 11){-----------------J1
R = q + 2;
q++;-----------------------J1
}
System.out.println(R);

(h) The following Java codes contain syntax errors. Rewrite the correct
version of each code.
[2 marks]

Java codes contain syntax errors Correct Version


int x = 200;
System.out.println (Value x = , x); int x = 100;
//Required output : Value x = 100 System.out.println (“Value x =” + x);

/* To output Hello string // To output Hello string


System.out.println(Hello); System.out.println(“Hello”);

4 (a) Construct a non-static user-defined method name statusAchievement,


which receives a value from a method call. The method display
message “Congratulation, you are among a top achiever ” if sales is
greater than RM5000. Otherwise display “Keep working hard”.
[4 marks]
void statusAchievement ( double sales){
if (sales>5000)----J1

5
System.out.print ( “Congratulation, you are among a top
achiever”); ---- J½
else
System.out.print ( “Keep working hard”); --- J½
}

*- void: J½, method name- J½, parameter list: ------J1

(b) Answer the following questions based on FIGURE 1.

FIGURE 1

(i) Identify the structure of the code shown in FIGURE 1.


[5 marks]

Method Structure Code


User-defined method name qMaths -----------------------------------------------------------------------1 mark
Example of pre-defined main(String[] args) ---------------------------------------------------------1 mark
method or
println() ---------------------------------------------------------1 mark
or
Math.pow(a,b) ---------------------------------------------------------1 mark
Argument/arguments 16,2 ---------------------------------------------------------1 mark
or
5, 2 ---------------------------------------------------------1 mark
Create object for method PowDemo objek=new PowDemo();-----------------------------------1 mark
Method call objek.qMaths(16,2); -----------------------------------------------------1 mark
or
objek.qMaths(5,2); ---------------------------------------------------------1 mark

(c) Computer Science Continuous Assessment is determined from several


quizzes and practical tests. Write a full Java program for n students that
can store each student’s name and marks from 2 practical tests in an
array name studID, pracOne, and pracTwo. The program will determine
the best student of the practical test by comparing the best score of

6
each student. The first line inputs n is representing the number of
students, followed by n lines, each represents the student’s name, first
practical test score, and second practical test score. Display the best
student with his/her highest score.
[15 mark]

Sample Input Sample Output

3 Best student is Safwan


Ayuni 80.6 97.5
Safwan 98.2 69.9 Highest score is 98.2
Delila 85.7 94.1

//PrePspm 2022

import java.util.Scanner;-------------------------J½

public class prePspm {-------------J½


public static void main (String [] args){------------J½

//create object
Scanner input = new Scanner (System.in);-----------J½

//get n size
int studSize = input.nextInt(); -----------J½

//declare an array
String [] studName = new String [studSize];--------J½
double [] pracOne = new double [studSize];---------J½
double [] pracTwo = new double [studSize];---------J½

double max = 0,highScore = 0;-------J½, J½


String bestStudent = " ";------ J½

//get input
for (int i = 0; i< studSize; i++)------J1,J1,J1
{
studName [i] = input.next();---------J½
pracOne [i] = input.nextDouble();--------J½
pracTwo [i] = input.nextDouble();-------J½

if (pracOne[i] > pracTwo[i])-------J1


max = pracOne[i];------- J½
else
max = pracTwo[i]; ------- J½
//endif

if (max>highScore)-------J1

7
{
highScore = max; ------- J½
bestStudent = studName[i]; ------- J½
}//endif
}//endfor

System.out.println("Best student is "+bestStudent);-----J½


System.out.print("Highest score is "+highScore); ------- J½

}
}

You might also like