SC025SetPastYear20182022 PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 31

SC 025

PAST YEAR QUESTIONS


2018/2019 – 2021/2022
Nama :

Kelas :

Content PSPM Page

2018/2019 1
2019/2020 6
2020/2021 13
2021/2022 19
PSPM II 2018/2019

Section B

1 (c) Mr Rahman plans to make a reservation for a hotel room in Langkawi Island. The basic rate is
RM250.00 per night and the sales and service charge is 15% of the room rate. Determine the total
payment if he books the hotel room for n nights. List the input, processes involved to calculate the
total payment and the output.

[4 marks]

Input

Process

Output

2 (a) Write a pseudocode to solve the following problem:

Read and determine the larger and smaller between two numbers. Print the larger number followed
by the smaller number if they are not equal. Otherwise, print the message – The numbers are equal.

[7 marks]

SC025 Past Years 2018- 2022 1


2 (b) Draw a flowchart to solve the following problem:

Display even numbers from 100 to 700 and add the total of the numbes. Display the total sum.

[10 marks]

3 Write Java assignment statements for the following algebraic equations.

(a) y = a2 + b2 – 4ac

[3 marks]

2 ( 𝑎2 + 𝑐 2 )+𝑎𝑏
(b) 𝑥 =
√𝑎+𝑐
[4 marks]

(c) Given the following Java codes, determine the value of c and y.

int a = 10, b = 5;
double c = 2, x = 4.2, y = 33, z = 2.0;
c=a+b–x/c;
y = 56 % 5 / 2 + a ;

c = __________________

y = __________________

SC025 Past Years 2018- 2022 2


(d) (i) Complete the given Java statements to produce the following output by using while loop.

output : 10, 9, 8, 7, 5, 4, 3, 2, 1, Bravo!

[6 marks]
int n = 10;

while ( n ___________) {

System.out.print ( _____ + “ ___” );

System.out.print ( _______________ ) ;

(ii) Write Java stements to determine the commisson (comm) based on the sales range given
in the following table.

[6 marks]

Sales (RM) Commission (comm)


10,000.00 – 25,000.00 0.05
25,000.01 – 40,000.00 0.15
Over 40,000.00 0.2

SC025 Past Years 2018- 2022 3


4 (a) Given the following code segmen, write Java code to read 10 numbers into the array
named numbers and calculate their average.

[4 marks]

Scanner in = new Scanner (System.in);

double [ ] numbers = new double [10], sum = 0, average;

____________________________________________________________________________
____________________________________________________________________________
____________________________________________________________________________
____________________________________________________________________________
____________________________________________________________________________
____________________________________________________________________________

System.out.println ( “ The average is “ + average );

(a) The women long jump competition has n athletes. Each athlete is given two jumps
and the winner is determined based on the longest jump distance (in metre). The
first line of input is n, representing the number of athletes followed by n lines, each
represents the athlete’s identification number, the distance of the first and second
jump. Write a complete Java program to find and print the winning athlete’s
identification number and her winning jump distance.

Input sample Output sample

3 The winner is athlete no. 101


200 2.4 4.0
The winning jum is 5.1m
101 4.9 5.1
223 3.8 3.3
[15 marks]

SC025 Past Years 2018- 2022 4


SC025 Past Years 2018- 2022 5
PSPM II 2019/2020

Section B

1 (a ) A customer can book a flight ticket through an online system. In each trancastion, a customer
has to pay total flight charges based on number of passenge rs and cabin class. Determine input,
process and output for the flight ticket booking problem.
[4 marks]

Input Process Output

1 (b) A student is required to determine volume of a cuboid on the measurements of length, width
and height in centimetre unit.

(i) Determine input, process and output for the volume calculation problem.
[5 marks]

Input Process Output

(ii) Complete the following Java program to calculate and display the volume with
appropiate message.
[5 marks]

class Cuboid{
public static void main(String[]args ){
double length= 4.5;
double width= 9.3;
double height= 7.8;
double volume;

____________________________________________________

_____________________________________________________

_____________________________________________________

}
SC025 Past Years 2018- 2022 6
1 (c) Write a pseudocode for each of the following scenario.

(i) Withdraw moner from automated teller machine (ATM)


[5 marks]

(ii) Determine and display whether a number entered is even or odd


[5 marks]

1 (d) Draw a flowchart with a selection structure to display “Weekend” if an input variable, day is
“Sat” or “Sun”. Otherwise display “Weekdays”.

[8 marks]

SC025 Past Years 2018- 2022 7


2 (a) The following formula is to calculate distance between two coordinate, (x1, y1) and (x2, y2).

distance =√ (𝑥2 − 𝑥1)2 + (𝑦2 − 𝑥2)2

Convert the formula into a Java assignment statement. [3 marks]

2 (b) Write a complete Java progam to dsiplay the conversion result of 28.5 degree Celcius to
Fahrenheit using the following formula.
9
Fahrenheit = degree in Celcius x + 32
5

[6 marks]

SC025 Past Years 2018- 2022 8


3 (a) Write a java code segment to calculate delivery cost in Ringgit Malaysia (RM) for a parcel based
on the weight, as given in the following table.

Weight (kg) Rate per kg (RM)


Under 1 kg 15.00
1 kg – 3 kg 13.00
Over 3 kg 10.00

[6 marks]

SC025 Past Years 2018- 2022 9


3 (b) (i) use while statement to rewrite the following Java segment.

for ( n=20; n >1; n = n-1)

if (n % 5 == 0 )

System.out.println (n);

[3 marks]

3 (b) (ii) Produce output for the java segment in 3 (b) (i)

SC025 Past Years 2018- 2022 10


4 (a) Write a Java public method named divisibleBy3() that returns true or false. The method
receives an int named number and evaluate whether number is divisble by 3 or not.

[5 marks]

4 (b) Write a Java program for a class named MaxClass to find a maximum value from an array. The
class shall contain main and findMax methods.

(i) In main method


- declare and initialize an array named myList to the following
elements {1, 4, 3, 5, 2}.
- assign the value returned by findMax to a variable named max.
- display max

(ii) The findMax method shall


- use for loop statement to determine the maximum value
- receive the array of integer values through its parameter
- return the maximum value

[11 marks]

SC025 Past Years 2018- 2022 11


SC025 Past Years 2018- 2022 12
PSPM II 2020/2021

1. DG Tech Sdn Bhd is a software development company in Kuala Lumpur, Malaysia. One of their
customers, DIY Mart requests a solution to allow their shoppers to shop online using mobile
applications. As a project manager of DG Tech, you set up a meeting with your team members to kick
off the project.

Based on the given scenario, answer the following questions.

(a) As a project manager, suggest the appropriate steps in sequence in order to develop the
solution.
[6 marks]

(b) Justify one (1) importance of problem analysis in project development.


[2 marks]

__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________

(c) Discuss two (2) benefits of testing step before delivering the system to the customers.
[4 marks]

SC025 Past Years 2018- 2022 13


2 You are writing a program to display student’s grade. The grade is based on mark as shown in the
table below. Use the appropriate control structure to display the grade when the user enters the
mark. If the user enters an invalid range of mark, the program should display message “Range of
mark should be between 0 to 100”.

Mark Grade
80 -100 A
65 - 79 B
50 - 64 C
40 - 49 D
0 - 39 E

Based on the given scenario, design the algorithm using a flowchart.

[14 marks]

SC025 Past Years 2018- 2022 14


3 (a) Declare and create an object for a class named MyCampus.

[2 marks]

3 (b) Give the output of the following Java statements.

System.out.print("**** ");
System.out.println("###");
System.out.print("**");
System.out.println("*");

[2 marks]

3 (c) Give the value of the following expressions

(i) true || false && 7 < 8 || ! (4 == 5);


(ii) (6%4) % 5;

[4 marks]

3 (d) Write Java statement(s) to accomplish the folloing process.

(i) Declare x and y as integer variables. Then, initialize x to 4 and y to 10.


[2 marks]

(ii) Assume p and q are integer variables. Swap the values of p and q. Declare additional
variables, if necessary.
[4 marks]

SC025 Past Years 2018- 2022 15


3 (e) Assume that all variables and input ( a Scanner) has been properly declared. Give the
output of the following program segment if the input is 30, 25, 11, 10 and -1.

num = input.nextInt();
sum = num;
while (num != -1)
{
num = input.nextInt();
sum = sum + num;
}

System.out.print(" Sum = " + sum);

[4 marks]

3 (f) Write a program segment using for to sum all the multiples of 5 between 1 to 100.

[6 marks]

SC025 Past Years 2018- 2022 16


3 (g) Give the output of the following program segment.

double A = 0;
for (int x = 3 ; x < 8 ; x = x+1) {
if(x < 4)
A = ( x * x) - 1;
else if (x < 6)
A = 5 + x ;
else
A = 20 - ( x * x );

System.out.println ("x = " + x + ",A(" + x + ") = " + A);


}

[5 marks]

4 Write a program that reads number of COVID-19 cases for each of the 14 states in Malaysia
on 31st August 2020 into an array. Based on TABLE 4, the program must determine.

i. The highest number of cases among thte 14 states on the specified day.
ii. The number of cases for each zone ( i.e red zone, yellow zone and green zone)

Number of Cases Zone Classifications


0 Green
1 - 40 Yellow
More than 40 Red

[15 marks]

SC025 Past Years 2018- 2022 17


SC025 Past Years 2018- 2022 18
PSPM II 2020/2021

1 (a) The wage to mow the yard of a house is based on the price of diesel used to mow it. The yard
to be mowed is shown in the shaded area given in the figure below.

House area

Built-in house area Yard

You are given the length and width of the house area and the length and width of the house. The
price of diesel used is Rm2.00 per square meter.

Identify the input. process and output to calculate and display the wage of moving the yard of the
house.

[10 marks]

Input Process Output

SC025 Past Years 2018- 2022 19


b) Draw a flowchart based on the following pseudocode about cake ordering

SC025 Past Years 2018- 2022 20


[15 marks]

SC025 Past Years 2018- 2022 21


2 (a) There are four characteristics of Object Oriented Programming (OOP).

Explain any two (2) of the characteristics

[4 marks]

__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________

(b) Write the Java assignment statements for the following algebraic equations.

(i) 𝑎 = 𝑦 2 𝑥 2 − 𝑦 + 2𝑥𝑦

[2 marks]

__________________________________________________________________________________
__________________________________________________________________________________

(ii) 𝑏 = √2𝑥 + 12 − 2𝑥

[2 marks]

__________________________________________________________________________________
__________________________________________________________________________________

SC025 Past Years 2018- 2022 22


(c) Determine the output of the following Java code segment.

int a = 3, c = 15;

double b = 0.5, d = 15 * b;

System.out.println(c % a – a % c);

System.out.println(4 * d / (b / a));

System.out.println((25 - c) / b * 13 + (-5));

[6 marks]

SC025 Past Years 2018- 2022 23


3 (a) The following Java program displays a line of asterisks ‘*’.

import java.util.Scanner;

public class Main{

public static void main(String[] args){

Scanner in = new Scanner(System.in);

System.out.println(“Enter size of line: ”);

int line = in.nextInt();

for (int i = 1; i <= line; i++){

System.out.print(“*”);

Modify the above program such that it displays a line with asterisks ”*” in even position and dashes ‘-
‘ in odd position. Output sample of the modified java program is as shown in figure below

Enter size of line:

-*-*-*-*-

[5 marks]

SC025 Past Years 2018- 2022 24


(b) Given below, two code segments that evaluates body temperature and COVID-19 related
symptoms

Code segment A – This segment evaluates whther the given body temperature (in Celcius) is between
35.0 (inclusive) and 38 (inclusive). If the value entered is not between this range, it will display “Invalid
value. Enter body temperature again : ”. Use an appropriate control structure to repeat this input
validation until the user enters a valid value.

Code segment B- This segment evaluates the Boolean input for variables cough, runnyNose, and
soreThroat. Use appropriate control structure to evaluate the variables. If all of them are false, it will
display “free from COVID-19”, otherwise it will display :Must be quarantined”.

Complete the following Java code segments that evaluates four (4) input values from a user

[10 marks]

import java.util.Scanner;

public class Covid19Checker {

public static void main (String args []) {

Scanner scanner = new Scanner (System.in);

double bodyTemp;

boolean cough, runnyNose, soreThroat;

System.out.println ("Enter body temperature : ");

bodyTemp = scanner.nextDouble () ;

Code segment A

SC025 Past Years 2018- 2022 25


System.out.println ("Has cough? : ");

cough = scanner. nextBoolean () ;

System. out.println ("Has runny nose? : ");

runnyNose = scanner. nextBoolean () ;

System.out.println ("Has sore throat? : ");

soreThroat = scanner. nextBoolean () ;

System.out.printin ("Temperature: " + bodyTemp);

System. out.printin ("Cough : " + cough);

System.out.printin ("Runny nose : " + runnyNose) ;

System.out.println ("Sore throat : "I + soreThroat) ;


Code segment B

} // end of main

} // end of class

SC025 Past Years 2018- 2022 26


4. An online restaurant has a salary system based on position level. The salary is being paid on weekly
basis. The restaurant has a cook (salary on hour basis) and a salesperson (fixed salary and sales
commision). The following is the details of the salary payment for each position level:

Position level : Cook

Salary paid per week: First 30 hours at a fixed rate of RM 20.00 per hour. The next following hours,
ovrtime rate at 1.5% of the fixed rate hourly.

Position level: Salesperson

Salary paid per week: Fixed salary of RM200.00 plus commision 10% of the total sales per week.

Write a complete Java program that prompts user to enter cook's hours worked per week, and
salesperson's total sales per week. Display the weekly salary for both cook and salesperson.

The process to calculate the amount of weekly salary for the cook uses the method calcSalaryCook
(int hour) which returns the weekly salary for the cook, and for the salesperson the process uses the
method calcSalarySalesPer (double sales) which returns the weekly salary for the salesperson.

SC025 Past Years 2018- 2022 27


SC025 Past Years 2018- 2022 28
1.0 INTRODUCTION TO PROGRAMMING

PSPM 1 2020/2021

(c) Differentiate between compiler and interpreter


[4 marks]
Compiler Interpreter

(d) Classify a suitable programming language paradigm based on the given description.
[3 marks]
Description Programming Language Paradigm
The program statements that express facts and
rules about problem within a formal logic system
The program consists of routines, subroutines or
functions to carry out a series of computational
steps.
A program that uses object that include both data
and function

PSPM 1 2018/2019

(c ) Complete the following table. [4 marks]

Program Translator Function Programming Language Type


Assembler

Compiler

SC025 Past Years 2018- 2022 29


PSPM 1 2015/2016

4. Give one (1) difference between low-level programming language and high-level
programming language

Low- Level Programming Language High- Level Programming Languange

PSPM 1 2011/2012

5. (a) Differentiate between Structured Programming and Object-Oriented Programming.


[4 marks]

Structured (procedural) Object-Oriented Programming


Programming
i. i.

ii. ii.

SC025 Past Years 2018- 2022 30

You might also like