The words you are searching are inside this book. To get more targeted content, please make full-text search by clicking here.

Koleksi Pra PSPM Kolej Kolej Lain ..

Discover the best professional documents and content resources in AnyFlip Document Base.
Search
Published by bm-3054, 2023-04-16 19:57:36

Pra PSPM SC025

Koleksi Pra PSPM Kolej Kolej Lain ..

5 (ii) b = 1; while(b > 8) { System.out.print(b + " "); b = b + 2; } [1 mark] ______________________________________________________________ (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] (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); (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); //Required output : Value x = 100 /* To output Hello string System.out.println(Hello);


6 4 (a) Construct a nont-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] (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 Example of pre-defined method Argument/arguments Create object for method Method call


7 (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 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 Ayuni 80.6 97.5 Safwan 98.2 69.9 Delila 85.7 94.1 Best student is Safwan Highest score is 98.2 END OF QUESTION PAPER


1 Name : _________________________________ Tutorial : ___________________________ ANSWER ALL QUESTIONS. 1. In order to solve a programming problem, the programmer needs to follow the correct problem solving steps. This is to ensure that no errors occur while the program is being run. a) What is problem solving? [2 marks] _______________________________________________________________________ _______________________________________________________________________ b) List the first two (2) steps in problem solving. [2 marks] _______________________________________________________________________ _______________________________________________________________________ c) Identify the steps in problem solving which involve in the situation. [3 marks] Test the system and record all the problem found. The design of pseudocode and flowchart. Ahmad is analysing the process of a system that his team needs to develop. d) In your opinion, why should the program be tested before delivering it to the user? [2 marks] _______________________________________________________________________ _______________________________________________________________________ Untuk Kegunaan Pemeriksa No. Soalan Markah 1 11 2 15 3 29 4 15 Jumlah GEMPUR PSPM SC025 SESI 2021/ 2022 KOLEJ MATRIKULASI SELANGOR


2 e) Justify one (1) importance of algorithm in problem solving. [2 marks] _______________________________________________________________________ _______________________________________________________________________ 2. a) KMS’s Bookstore is doing a End Year sales promotion. Total price will be calculated based on quantity and price of the items. if a customer purchases above RM15.00, the customer will be given 15% discount. Otherwise, 5% discount will be given. Calculate the price that a customer should pay. Based on the given scenario, design the algorithm by using a pseudocode. [7 marks]


3 b) Draw a flowchart to solve the following problem: Display multiplication numbers of 3 from 50 to 300 and add the total of the numbers. Display the total added numbers. [8 marks]


4 3. (a) Write Java assignment statements for the following algebraic equations. (i) y = ax 2 + bx + c [2 marks] (ii) = ( ( + 1) 2 ) 2 [3 marks] (b) Given the following Java codes. int a = 10, b = 5; while (a <= 50) { a = a + b; } System.out.print (a); (i) State the output(s) based on 3(b). [1 mark] (ii) Rewrite the code using for loop. [3 marks]


5 c) Rewrite the below Java assignments in the correct version. [3 marks] (*assume all the variables have been declared.) d) What is the output of the following code segments? (*assume all the variables have been declared.) [3 marks] Java Statements Output i. y = 10; if (y > 7) System.out.print ("AAA"); System.out.print ("BBB"); ii i . for (u = 1; u > 3; u = u+1) { System.out.print (u + " " ); } iii. System.out.print(“### “); System.out.println(“****”); System.out.print(“##”); System.out.print(“/n**”); i. char aChar = 5.5; ii. if (salesAmount >10 && <50) iii. String aName; String anotherName; if (aName == anotherName)


6 e) i) Declare and create an object for a class named CalcAverage. [2 marks] Give the value of following Java expressions. [2 marks] ii) false || 6 > 12 && !(3==7) ______________________________________________________________ iii) ( 7 % 5) % 4 ______________________________________________________________ f) i) Based on the following Java code, the purpose of the Java code is to calculate the sum of number from 10 to 100 increment by 10. Identify the type of errors and fix the Java code: [2 marks] int counter = 10; int sum = 0; while (counter <=100){ sum = sum + counter; add 10 to counter;} System.out.print(“Sum of all number is”+sum); ii) Write Java statement(s) to accomplish the following process. [2 marks] Declare a and b as integer variables. Then, initialize a to 10 and b to 20.


7 iii)Write a Java program segment for : A Method named calcNumbers that will accept two integer numbers and return the product value if both numbers are odd, return the total value if both numbers are even or return the division value if both numbers are not odd or even. [6 marks] 4. Blood pressure reading basically has two numbers, for example 125/85 mmHg. The top number (125) is called systolic while the bottom (85) is called diastolic. Based on these reading, the level of blood pressure of a person can be determined, such as low, ideal, prehigh or high. Write a complete Java program that performs the following tasks: Request the reading of blood pressure for systolic and diastolic for n persons. Store the data in the arrays named arrSystolic and arrDiastolic respectively. Find minimum reading of diastolic. Count the number of person that can be categorized as low blood pressure where the reading of systolic is less than 100 and diastolic is less than 60.


8 [15 marks]


SKEMA JAWAPAN GEMPUR PSPM SESI 2021/ 2022 Question Answer Mark 1.(a) The process that programmers follow when solving problems that require a computer solution. J2 (b) Problem analysis design a solution J1 J1 (c) Testing Design a solution Problem analysis J1 J1 J1 (d) to demonstrate the program correctness and to ensure that the program meet user requirement J2 (e) to identify a step by step description of a method to solve a problem or to identify an effective procedure for solving a problem J2 2. (a) Start Read quantity, price ---1m total price = quantity x price --1m if (total price > 15) --1m discount = 0.1 x total price --1m nett price = total price - discount --1m else discount = 0.05 x total price --0.5m nett price = total price - discount --0.5m end if Print nett price --1m Stop


2. (b) Start, Stop – J0.5 Initialize number, sum – J1 number ≤300 – J1 number %3 = 0 – J1 sum = sum + number - J1 number = number + 1 - J1 print sum – J1 print number – J1 Correct symbol – J0.5 Any acceptable answers 3(a) (i) y = (a * x * x) + (b * x) + c; or y = a * Math.pow( x , 2) + b * x + c; J2 (ii) = ( ( * ( + 1))/2) * ( ( * ( + 1))/2); or = Math.pow ( * ( + 1))/2, 2); J2 3(b)(i) 55 J2 (ii) int a, b = 5; for (a = 10;a <= 50;a = a + b) { } System.out.print (a); J1 J1 J1


3 (c) (i) double aChar = 5.5; J1 3 (c) (ii) if (salesAmount >10 && salesAmount <50) J1 3 (c) (iii) String aName; String anotherName; if (aName.equals(anotherName)) J1 3 (d) i AAABBB J1 3 (d) ii No Output J1 3 (d) iii ### **** ##/n** J1 3(e) (i) CalcAverage obj = new CalcAverage(); J2 3 (e) (ii) False J1 3 (e) (iii) 2 J1 3 (f)(i) Syntax error - add 10 to counter; J1 counter = counter + 10; J1 J2 3(f)(ii) int a = 10; int b = 20; J1 J1 3(f)(iii) int calcNumbers(int num1, int num2) { int value; if(num1 % 2 != 0 && num2 % 2 != 0) value = num1 * num2; else if(num1 % 2 == 0 && num2 % 2 == 0) value = num1 + num2; else value = num1/ num2; return value; } *any acceptable answer J2 J1 J1 J1 J1


4 import java.util.Scanner; public class BloodPressure { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter number of person : "); int n = sc.nextInt(); int arrSystolic[] = new int[n]; int arrDiastolic[] = new int[n]; int minDiastolic = arrDiastolic[0]; for(int i = 0; i < n; i++) { System.out.print("Enter blood pressure for systolic and diastolic : "); arrSystolic[i] = sc.nextInt(); arrDiastolic[i] = sc.nextInt(); if(arrDiastolic[i] < minDiastolic) minDiastolic = arrDiastolic[i]; } System.out.println("Minimum reading for Diastolic : "+minDiastolic); int sumLow = 0; for(int j = 0; j < n; j++) { if(arrSystolic[j] < 100 && arrDiastolic[j] < 60) sumLow = sumLow + 1; } System.out.println("The number of person that can be categorized as low blood pressure : "+sumLow); } } or import java.util.Scanner; public class BloodPressure { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter number of person : "); int n = sc.nextInt(); int arrSystolic[] = new int[n]; int arrDiastolic[] = new int[n]; int minDiastolic = arrDiastolic[0]; J1 J1 J1 J1 J2 J0.5 J0.5 J1 J1 J1 J1 J2 J1 J1 J1 J1 J1 J1


int sumLow = 0; for(int i = 0; i < n; i++) { System.out.print("Enter blood pressure for systolic and diastolic : "); arrSystolic[i] = sc.nextInt(); arrDiastolic[i] = sc.nextInt(); if(arrDiastolic[i] < minDiastolic) minDiastolic = arrDiastolic[i]; if(arrSystolic[i] < 100 && arrDiastolic[i] < 60) sumLow = sumLow + 1; } System.out.println("Minimum reading for Diastolic : "+minDiastolic); System.out.println("The number of person that can be categorized as low blood pressure : "+sumLow); } } J1 J2 J0.5 J0.5 J1 J1 J2 J1 J1 J1 *any suitable answer


Click to View FlipBook Version