SC025 ConquerSET1 (Q)
SC025 ConquerSET1 (Q)
SET 7
Computer Science 2 Sains Komputer 2
Semester II Semester II
Session 2022/2023 Sesi 2022/2023
2 hours
SET 1 2 jam
CONQUER
TAKLUK
2 Identify input, process and output based on the given problem statement.
(a) Mangoes, rambutans, and durians are sold at RM8 per kilogram, RM10 per
kilogram, and RM25 per kilogram respectively. Find the total price for all the
fruits bought by a customer.
[3 marks]
Input Process Output
kgMango Calculate totalPrice totalPrice
kgRambutan
kgDurian
2
SC025: Computer Science 2
(b) Jerseys are sold based on the following table. Find the total price of jerseys
bought by a customer.
(c) Find the total price of items bought by a customer until negative value is
entered.
[4 marks]
Input Process Output
itemPrice Repeat while itemPrice totalPrice
> 0, read itemPrice,
calculate totalPrice.
3
SC025: Computer Science 2
(a) Calculate the sale price of three shirts after given 79% discount.
[6 marks]
Begin
Input shirt1Price, shirt2Price, shirt3Price
salePrice = 21% x (shirt1Price + shirt2Price + shirt3Price)
Display salePrice
End
(c) Repeat 24 times, read mark, determine status ("Pass" or "Fail") based on mark.
[7 marks]
Begin
Input mark
counter = 0
While (counter < 24)
If (mark ≥ 40)
Display "Pass"
Else
Display "Fail"
End If
counter = counter + 1
End While
End
4
SC025: Computer Science 2
[1 mark]
Hello
World!Hello, World!
Hello, World!
(ii) Read a symbol and store it into a variable. (Assume Scanner object is
sc)
[1 mark]
5
SC025: Computer Science 2
(i) z = mx ÷ cy2
[1 mark]
z = m*x / (c*y*y);
−𝑏𝑏+√𝑏𝑏 2 −4𝑎𝑎𝑎𝑎
(ii) root 1 = 2𝑎𝑎
[1 mark]
root1 = (-b + Math.sqrt(b*b-4*a*c)) / (2*a);
5 (a) Construct program segment by using sequence control structure to find the
total and the average of three (3) marks. (Assume the Scanner object is obj)
[3 marks]
double mark1, mark2, mark3, total, average;
mark1 = obj.nextDouble();
mark2 = obj.nextDouble();
mark3 = obj.nextDouble();
total = mark1 + mark2 + mark3
average = total / 3;
System.out.println("The total is " + total)
System.out.println("The average is " + average)
6
SC025: Computer Science 2
(b) Construct program segment by using selection control structure to find the
status of a student ("Pass" or "Fail") based on mark. (Assume the Scanner
object is input)
[4 marks]
double mark;
mark = input.nextDouble();
if(mark < 40)
System.out.println("Fail");
Else
System.out.println("Fail");
int i=0
for(int a=3; a<57; a++) {
System.out.println("\n\tHello, World!");
i = i + 1;
}
[4 marks]
int i=0;
int a=0;
while(a <57) {
System.out.println("\n\tHello, World!");
i = i + 1;
a++;
}
(ii) Write a method call for the above method definition answered in
6(a)(i).
[2 marks]
boolean status = determineSquare(length, width);
(b) Construct programs that perform one-dimensional array operations to find the
average, maximum and minimum value among 100 numbers.
7
SC025: Computer Science 2
[9 marks]
import java.util.*;
class Numbers {
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
// Variable declaration
double[] numbers = new double[100];
double total=0, average=0, max, min;
// User-friendly message
System.out.print("Enter twelve (100) rain falls:
");
// Input statement
for(int i=0; i<100; i++) {
numbers[i] = input.nextDouble();
}
max = numbers[0];
min = numbers[0];
for(int i=0; i<100; i++) {
if(numbers[i] > max) {
max = numbers[i];
}
if(numbers[i] < min) {
min = numbers[i];
}
}
// Output statement
System.out.println("The average is " + average);
System.out.println("The maximum is " + max);
System.out.println("The minimum is " + min);
}
}
END OF QUESTIONS
KERTAS SOALAN TAMAT