0% found this document useful (0 votes)
2 views11 pages

Class Test 2 A MEMO

This document is a memo for Class Test 2 A for the Principles of Programming and Introduction to Programming courses, scheduled for May 30, 2025. It includes test instructions, questions covering true/false statements, multiple choice, short answers, output prediction, pseudocode writing, error spotting, and Java coding tasks. The test is designed for first-year ICT students and has a total of 35 marks.

Uploaded by

mesomanana
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)
2 views11 pages

Class Test 2 A MEMO

This document is a memo for Class Test 2 A for the Principles of Programming and Introduction to Programming courses, scheduled for May 30, 2025. It includes test instructions, questions covering true/false statements, multiple choice, short answers, output prediction, pseudocode writing, error spotting, and Java coding tasks. The test is designed for first-year ICT students and has a total of 35 marks.

Uploaded by

mesomanana
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/ 11

PPAFO5D/TROF05D CLASS TEST 2 A - MEMO May 2025

Faculty of Information and Communication Technology


ICT First Years and Foundation Unit

Principles of Programming and


Introduction to Programming
(Extended) (Year 1)

PPAF05D & TROF05D


CLASS TEST 2 A
MEMO
30 May 2025 Examiner: VL Baloyi

Duration: 90 min
Total: 35 Moderator: KS Tshehla
Full Marks: 35
Number of Pages: 11

Test Instructions
1. Read the instructions at the start of each question carefully.
2. Answer all questions on the Electronic Campus (EC) platform.
3. Use Notepad++ and the console only — no IDEs (like Eclipse, IntelliJ,
etc).
4. Test (debug) your code before submitting your answers.
5. Copy and paste your final answers into EC (do not cut and paste).
6. Keep a backup of each program in Notepad++ until you’ve confirmed your
submission.
7. Only scientific, non-programmable calculators are allowed.
8. Cellphones are not allowed during the test.
9. No sharing of calculators or stationery.

1
PPAFO5D/TROF05D CLASS TEST 2 A - MEMO May 2025

Question 1 (TRUE or FALSE) [5]

State whether the following statements are true or false.


Statements Answer
1.1 String is a primitive data type in Java. False
1.2 The expression x++ increases the value of x by 1 after it is used True
in an expression.
1.3 result+=10 is a valid compound assignment statement True
1.4 The method print() moves the cursor to the next line after False
printing.
1.5 Java code must be written inside a method named start(). False

Question 2 (Multiple choice) [5]


2.1 What is the correct way to declare a constant for tax percentage?
A. final double TAX = 0.15; A
B. const double tax = 0.15; B
C. TAX = final 0.15; C
D. double final TAX = 0.15; D

2.2 What is the correct method to read a String from the user?
A. readLine() A
B. keyboard.nextLine() B
C. input.nextString() C
D. String(); D

2.3 Which of the following is a valid identifier?


A. 1number A
B. total_value B
C. float C
D. @amount D

2.4 What will be the result of this operation: 7 / 2 in Java using integers?
A. 3 A
B. 3.5 B
C. 4 C
D. 0 D

2
PPAFO5D/TROF05D CLASS TEST 2 A - MEMO May 2025

2.5 What does the Scanner class do?


A. Prints text to the screen A
B. Compiles the Java code B
C. Stores constants C
D. Reads input from the keyboard D

Question 3 (SHORT ANSWERS) [5]


One-line answers only. Do not write more than that as it will be marked wrong.
3.1 What is the purpose of the main() method in a Java program? (1)

The main() method is essential for launching a standalone Java


application.
3.2 What does the .nextInt() method return? (1)

integer
3.3 What is the difference between print() and println()? (2)

print() - Prints text without moving to a new line.


println() - Prints text and then moves the cursor to a new line.
3.4 What keyword is used to define a class in Java? (1)

Class

3
PPAFO5D/TROF05D CLASS TEST 2 A - MEMO May 2025

Question 4 (Predict the output) [5]


Given a = 9, b = 4, d = 3, show all calculations to determine the value of x, where:
x = a \ b mod 5 * d ^ 2

A
B
C
D
E
Solution:
x = 9 \ 4 mod 5 * 3 ^ 2
x = 9 \ 4 mod 5 * 9
x = 2 mod 5 * 9
x=2*9
x = 18

4
PPAFO5D/TROF05D CLASS TEST 2 A - MEMO May 2025

Question 5 (Write pseudocode) [5]


Musa is a student assistant working part-time at the university library. Each month, he records the number of hours he worked and
multiplies it by the hourly pay rate to calculate his salary. (You only need to fill in the letters indicated with the correct code)
Write pseudocode for a program that (The class name is SalaryCalculator):
• Asks Musa to enter his name.
• Asks how many hours he worked this month.
• Asks for his pay rate per hour.
• Calculates his total salary.
• Displays a message showing his name and the salary amount he will receive.
Example:

5
PPAFO5D/TROF05D CLASS TEST 2 A - MEMO May 2025

A
begin
B
begin
//Declare variables
String sName
int iHoursWorked
double rPayRate, rSalary

//Input
C
D
E
F
G
H

//Process
I

//Output
J
end
end

6
PPAFO5D/TROF05D CLASS TEST 2 A - MEMO May 2025

Possible answer:

Marks Letter Reason


0.5 A Proper class name as given
0.5 B Having the main method
0.5 C Display for input
0.5 D enter for input
0.5 E Display for input
0.5 F enter for input
0.5 G Display for input
0.5 H enter for input
0.5 I Correct calculation
0.5 J Correct display

7
PPAFO5D/TROF05D CLASS TEST 2 A - MEMO May 2025

Question 6 (Spot and Fix the Error) [5]


The following Java program allows the user to enter their product's price, then
compares it to a random competitor price between R1 and R5000. It should display
the higher price, formatted to two decimal places.
However, the code below contains multiple errors. Your task is to identify and correct
them.

import java.util.Scanner;

public class PriceBattle


{
public static void main(String[] args)
{
//Declare
Scanner scan = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("#.00");
double userPrice, compPrice, max;

//Input
System.out.print("Enter your price: ");
userPrice = scan.nextdouble;

//Randomize price
compPrice = 1 + Math.random(5000);

//Get the maximum


max = math.min(userPrice, max);

System.out.println("Higher price is R " + df.format(Max));


}
}

Possible solution:

8
PPAFO5D/TROF05D CLASS TEST 2 A - MEMO May 2025

9
PPAFO5D/TROF05D CLASS TEST 2 A - MEMO May 2025

Question 7 (Write Java code) [5]


Thuli wants to create a program that calculates the average of three test marks
and displays the result to the user. She also wants the result to show two decimal
places.
Write a complete Java program that:
• Asks the user to enter their name
• Asks for three test marks (integers)
• Calculates the average of the three marks (the result must be a double, use
casting if necessary)
• Displays the name and the average, rounded to two decimal places
You may use either:
• DecimalFormat
or
• Math.round() with manual division to round to two decimal places.

Possible solution:
Component Description Marks
1. Input Handling Accepts name and 3 test marks 1
2. Variable Declarations Declares all required variables 1
3. Type Casting Uses (double) to get accurate average 1
4. Rounding Method Uses either DecimalFormat or Math.round() correctly 1
5. Output Displays name and rounded average to two decimal 1
places

10
PPAFO5D/TROF05D CLASS TEST 2 A - MEMO May 2025

11

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy