PRG510S - PROGRAMMING 1 - 2ND OPP - JAN 2025


PRG510S - PROGRAMMING 1 - 2ND OPP - JAN 2025



1 Page 1

▲back to top


n Am I BI A u n IVER s ITY
OF SCIEnCE RnD TECHnOLOGY
FACULTY OF COMPUTING AND INFORMATICS
DEPARTMENTOF SOFTWAREENGINEERING
QUALIFICATION: BACHELOROF COMPUTERSCIENCE,BACHELOROF COMPUTERSCIENCE
IN CYBERSECURITYAND BACHELOROF INFORMATICS
QUALIFICATIONCODE:07BCMS, 07BCCY,07BAIT
LEVEL:5
COURSE:PROGRAMMING 1
COURSECODE:PRG510S
DATE:JANUARY2025
PAPER:THEORY
DURATION: 2 HOURS
MARKS: 85
SUPPLEMENTARY/ SECONDOPPORTUNITYEXAMINATION QUESTION PAPER
EXAMINER
MR MIKE KALE
MODERATOR:
MR STEVENTJIRASO
INSTRUCTIONSTO STUDENTS
1. Answer ALL the questions.
2. Read all the questions carefully before answering.
3. Number the answers clearly.
THIS QUESTIONPAPERCONSISTSOF 11 PAGES
(Including this front page)

2 Page 2

▲back to top


Question Two
[8 Marks]
Write a complete Java program that calculates and displays the result of a number 'x' raised
to the power of a number 'y', where 'x' and 'y' are integers provided by the user. For the
simplicity of the solution, assume that that the exponent 'y', is always equals to or greater
than zero. The program should display the results.
Below is part of the java code to guide you by filling in the blanks, however, you are also
free to write your own Java code from scratch. Complete the code below based on the
requirements above. Note: x is the base, and y is the exponent.
package secondexam;
[1 Mark]
public class QuestionTwoD {
public static void main(String[] args) {
[1 Mark]
System.out.print("Enter the base (x): ");
int x = sc.nextlnt();
System.out.print("Enter the exponent (y): ");
int y = sc.nextlnt();
long result = 1;
if( __ ) {
for( _____
[1 Mark]
){
}
System.out.println("Result:
}
sc.close();
[2 Marks]
[2 Marks]
" ___ );
[1 Mark]
Sample Run
Enter the base (x): 2
Enter the exponent (y): 3
Result: 8
Page 10 of 11

3 Page 3

▲back to top


Question Three
[12 Marks]
You are designing a basic login system. The system stores a username and password in two
separate variables and allows a user to log in by entering the correct credentials (username
and password).
• If the credentials are incorrect, the user is given up to 3 attempts to enter the correct
username and password.
• If the user fails all 3 attempts, print a message saying, "The account is locked!".
• Otherwise print a message saying, "Login Successful."
Below is the username and password. Declare variables to store the username and
password and assign the values as follows:
Username: student
Password: 12345
Write a Java program that prompts the user for a username and password, and checks
whether they match the stored credentials.
Question Four
[20 Marks]
You are tasked with creating a simple movie ticket booking system. The system allows
customers to book tickets for a specific movie. The movie prices vary based on age:
• Children (under 12 years old) pay NAD 80.00,
• Adults (12 to 65 years old) pay NAO 120.00,
• And seniors (over 65 years old) pay NAD 100.00.
Declare a static method named calculatePrice(age) that takes age as a parameter and
returns the price of the movie ticket based on the age. This method MUST NOT be void, it
must return the price of the movie ticket.
Next, declare a static method named bookTicket{price, numberOfTickets) that takes the
price and number of tickets as parameters and calculates and display/print the total cost of
the tickets based on the price and the number of tickets requested. This method MUST be
void.
Write a complete Java program to implement this movie ticket booking system. Your
solution must include methods calls.
****************************** ENDOF EXAM********************************
Page11 of 11