PRG510S - PROGRAMMING 1 - 2ND OPP - DEC 2025


PRG510S - PROGRAMMING 1 - 2ND OPP - DEC 2025



1 Page 1

▲back to top


nAmlB IA untVERSITY
OF SCIEnCE Ano TECHnOLOGY
FACULTY OF COMPUTING AND INFORMATICS
DEPARTMENT OF SOFTWARE ENGINEERING
QUALIFICATION: BACHELOR OF COMPUTER SCIENCE, BACHELOR OF COMPUTER SCIENCE IN
CYBER SECURITY AND BACHELOR OF INFORMATICS
QUALIFICATION CODE: 078CMS, 07BCCY, 07BAIT
LEVEL: 5
COURSE: PROGRAMMING 1
COURSE CODE: PRG510S
DATE: DECEMBER 2025
PAPER: THEORY
DURATION: 3 HOURS
MARKS: 75
SUPPLEMENTARY/ SECOND OPPORTUNITY EXAMINATION QUESTION PAPER
EXAMINER(S)
MR MIKE KALE
MODERATOR:
MS NDINELAGO NASHANDI
INSTRUCTIONS TO STUDENTS
1. Answer ALL the questions.
2. Read all the questions carefully before answering.
3. Number the answers clearly.
THIS QUESTION PAPER CONSISTS OF 10 PAGES
(Including this front page)
Page 1 of 10

2 Page 2

▲back to top


SECTION A: Multiple choices and True and false Questions
[10 Marks)
The section consists of10 questions. Answer ALL the questions.
1. Which keyword is used to define a method in Java? (1 Mark)
A. define
B. function
C. method
D. void
2. Which of the following is used to handle exceptions in Java? [1 Mark)
A. try
B. catch
C. finally
D. All of the above
3. Which method is the entry point for a Java program? [1 Mark]
A. start()
B. main()
C. run()
D. public()
Page 2 of 10

3 Page 3

▲back to top


4. What will be the output of the following code? (1 M ark]
int X = 10;
if (x > 5){
int y = X + 5;
}
Syst em.out.println(y);
A. 5
B. 10
C. 15
D. Compilation Error
5. What will be the output of the following code? (1 Mark]
inti= 5;
intj = i++;
System.out.pri ntl n(j);
A. 0
B. 5
C. 6
D. Compilation Error
6. Java uses curly braces { } to define blocks of code. (1 Mark]
A. True
B. False
Page 3 of 10

4 Page 4

▲back to top


7. Java is not a platform-independent programming language. (1 Mark]
A. True
B. False
8. The finally block always executes whether an exception is thrown or not. (1 Mark]
A. True
B. False
9. Java is a case-sensitive programming language. (1 Mark]
A. True
B. False
10. In Java, System.println() is used to display an output. (1 Mark]
A. True
B. False
Page 4 of 10

5 Page 5

▲back to top


SECTION 8: BASIC QUESTIONS
[11]
This section consists of5 questions. Answer ALL the questions.
When is answering the questions in this section, it is not necessary to include the
class and main method.
Question One [2 Marks)
You are given the following variable declaration in Java,
int a= 5;
Use the+= operator to add 3 to the variable a, and then print the result of the variable a to
the console.
Question Two [2 Marks)
Declare a constant integer variable called MAX SIZE and assign it a value 100.
Question Three (2 Marks]
Declare a variable of data type float ca lled price and assign it the value 15.95.
Question Four (2 Marks)
What is a stack overflow error in recursion? When does it occur?
Question Five (3 Marks]
What is the difference between checked and unchecked exceptions in Java? Give one
example of each. Only write the lines of code that could lead to a checked or an unchecked
exception. You do not need to write a complete Java program.
Page 5 of 10

6 Page 6

▲back to top


SECTION C: DEBUGGING / CODETRACING QUESTIONS
[10]
This section consists of 1 question. Answer ALL the questions.
Identify and correct any errors in the given Java code below. identify which lines (numbers
on the left) have errors, describe the error and suggest how you will fix it. Ignore the
absence of the main class or any surrounding structure. Just focus on correcting the code
that is shown.
Question One (10 M arks]
1. grade = 'A';
2. int score= 96.2;
3.
4. switch (g) {
5.
case 'A':
6.
System.out.println("Excellent");
7.
if (score >= 95) {
8.
System.out.println("Outstanding performance!");
9.
}
10.
break;
11.
12.
'B':
13.
System.out.println('Good');
14.
if (score >= 85) {
15.
System.out.println("Very good!");
16.
17.
break;
18.
19. case "C":
20.
System.out.println("Average");
21.
break;
22.
23.
case 'D':
24.
System.out.println("Below average");
25.
26.
27. case 'F':
28.
System.out.println("Failing grade")
29.
break;
30.
Page 6 of 10

7 Page 7

▲back to top


31. default:
32.
System.out.println("lnvalid grade");
33.
Page 7 of 10

8 Page 8

▲back to top


SECTION D: CODING
[441
This section consists of4 questions. Answer ALL the questions.
Question One [8 Marks]
Given the array below called numbers,
Write a complete Java program that performs the following tasks:
Create an integer array called numbers, that comes initialised/populated with 5 elements,
as shown above. Using a loop, iterate through each element of the array, and square each
element (i.e., multiply the element by itself) and store the result in another array called
myNumbers. After squaring all the elements and storing them in the array called
myNumbers, use a loop to print the squared elements/numbers from the array called
myNumbers to the console.
Sample Run
Squared array elements:
4 16 36 64 100
Page 8 of 10

9 Page 9

▲back to top


Question Two [S Marks]
You're tasked with developing a simple interest calculator for a bank. The program should
prompt the user to enter the initial deposit amount, the annual interest rate (expressed as a
percentage), and the number of years the money will be invested. The initial deposit
amount and the annual interest rate must be decimal numbers. Using these inputs,
calculate the final amount using the following simple interest formula:
Final Amount = Principal+ (Principal x Rate x Time)/ 100.
After calculating the final amount, the program should check if the final amount exceeds
N$15 000. If it does, print "High Return", otherwise, print "Standard Return". Your program
must also print the final amount to the console. Write a complete java program that
performs these tasks.
Question Three [9.5 Marks]
Write a Java program that will accept 5 students in total from the user and count the
number of fulltime and parttime students respectively. The program should prompt the user
to enter "FT" for fulltime students and "PT" for parttime students. If anything other than
"FT" or "PT" is entered, reject the input and print an error message. After all valid entries,
print the number of fulltime and parttime students respectively to the console. The program
should only accept uppercase letters, for example, "FT" not "ft" and "PT" not "pt".
NOTE: DO NOT USE ARRAYS
Sample Run
Enter study mode for student 1 (FT for Fulltime, PT for Parttime): FT
Enter study mode for student 2 (FT for Fulltime, PT for Parttime): FT
Enter study mode for student 3 (FT for Fulltime, PT for Parttime): GH
Invalid input. Please enter only 'FT' or 'PT'.
Enter study mode for student 3 (FT for Fulltime, PT for Parttime): pt
Invalid input. Please enter only 'FT' or 'PT'.
Enter study mode for student 3 (FT for Fulltime, PT for Parttime): PT
Enter study mode for student 4 (FT for Fulltime, PT for Parttime): FT
Enter study mode for student 5 (FT for Fulltime, PT for Parttime): PT
--- Total Student Summary ---
Total Fulltime Students: 3
Total Parttime Students: 2
Page 9 of 10

10 Page 10

▲back to top


Question Four [21.5 Marks]
A telecom company gives its subscribers 3072 MB for 7 days for a specific fee. Write a java
program for the telecom company that does the following:
1. Prompt the user to enter how much data (in MB) was used each day, for 7
days. Use a loop for your solution.
2. Store each day's data in an array called data. Use a loop for your solution.
3. Warn the user if they exceed 80% of the weekly 3072 MB in each day.
Also create a method named calcDataUsage() that accepts the data array as a parameter.
The calcDataUsage() method should do the following:
1. Calculate the total data used in 7 days. Use a loop for your solution.
2. Print the total data used in 7 days to the console.
3. Print the message "You have exceeded your weekly data!", if the total data
used in 7 days exceeds 3072 MB.
4. Print to the console how many days the data used was:
Under 300 MB
Over 300 MB
YOU MUST USE LOOPS FOR YOUR SOLUTION.
NOTE: The logic to calculate and print the total data used, to print the message "You have
exceeded your weekly data!" and how many days the data used was under 300 MB, and
how many days the data used was over 300 MB must be implemented in a separate method
called calcDataUsage().
******************************* END OF EXAM **********************************
Page 10 of 10