PRG510S - PROGRAMMING 1 - 2ND OPP - JAN 2024


PRG510S - PROGRAMMING 1 - 2ND OPP - JAN 2024



1 Page 1

▲back to top


n Arn I BI A u n IVER s ITY
OF SCIEnCE Ano TECHnOLOGY
FACULTOYF COMPUTINGAND INFORMATICS
DEPARTMENTOF SOFTWAREENGINEERING
QUALIFICATION: BACHELOROF COMPUTERSCIENCE,BACHELOROF COMPUTERSCIENCE
IN CYBERSECURITYAND BACHELOROF INFORMATICS
QUALIFICATIONCODE:07BCMS, 07BCCY,07BAIT
LEVEL: 5
COURSE:PROGRAMMING 1
COURSECODE: PRG510S
DATE:JANUARY2024
PAPER:THEORY
DURATION: 2 HOURS
MARKS: 100
SECONDOPPORTUNITY/SUPPLEMENTARYEXAMINATION QUESTION PAPER
EXAMINER
DR AMBROSEAZETA
MODERATOR:
MR STEVENTJIRASO
INSTRUCTIONS
1. Answer ALL the questions.
2. Read all the questions carefully before answering.
3. Number the answers clearly.
THIS QUESTION PAPERCONSISTSOF 5 PAGES
(Including this front page)
1

2 Page 2

▲back to top


SECTIONA: TRUEOR FALSE
This section consist of 20 questions. Answer all the questions
Each correct answer is allocated 2 Marks
Write True or False for Questions 1 to 20.
1. It is compulsory to insert package in a Java program on VPL elearning.
[2 Marks]
2. Every Java program requires at least one class
[2 Marks]
3. In Java, the following statements are allowed: System.out.println(); or
System.out.print(); or System.out.printf();
[2 Marks]
4. Once an Array is declared, the size cannot be changed.
[2 Marks]
5. An Array can store only values of the same type
[2 Marks]
6. print() - prints string inside the bracket and the cursor moves to the
beginning of the next line
[2 Marks]
7. In Java, the keywords: main, Main, and mAin are the same
[2 Marks]
8. A variable is a location in the library to hold data.
[2 Marks]
9. This statement should be declared as char strl = "Java Programming";
[2 Marks]
10. The statement: /(7 = Ml/Nl * N2 is the same as 1<7= Ml/nl *n2
[2 Marks]
11. You can pass data, known as parameters, into a method.
[2 Marks]
12. scanner9 is a valid variable name.
[2 Marks]
13. The output of {8*2)/4-1 using precedence operator rule is: 9
[2 Marks]
14. In java the statement int loge is a valid statement
[2 Marks]
15. Every Java source file must bear the same name with the package and the
same name with the public class
[2 Marks]
16. Division by O or out of range array is an example of exception handling
[2 Marks]
17. The statement
double difference== numl - num2 is valid
[2 Marks]
18. int[] numsl= { 1, 2, -2, 3, 4, 5, 6} declares an integer array with the following
elements: 1, 2, -2, 3, 4, 5, 6
[2 Marks]
19. In Java, the identifiers DSEstudent, DSEStudent and DSEsTudent are all the same. [2 Marks]
20. Student_Mark is a Java keyword
[2 Marks]
SECTIONB: FILLTHE GAP
Copy and complete the table below.
Question Data Type
Value
Number
1
80.5
2
D
3
True
4
25003453.902
5
"Distinction
Student!"
6
21
Example of declarations
and assignment
Marks
[2 Marks]
[2 Marks]
[2 Marks]
[2 Marks]
[2 Marks]
[2 Marks]
2

3 Page 3

▲back to top


SECTIONC: CODESNIPPET
This section consist of 3 questions. Answer all the questions
Each correct answer to a question is allocated 8 Marks
Question One
(A) What will be the output of this Java code snippet?
public class example1 {
public static void main(String[] args) {
int a= 10;
int b = 12;
b++;
System.out.println(a+b);
a++;
[8 Marks]
(4 Marks)
(B} What is the output of the following Java code snippet:
public class example2 {
public static void main(String[] args) {
int[] X = {120, 200, 8};
for(int i = O; i < x.length; i++){
System.out.print(x[i] + "");
(4 Marks)
Question Two
(A) What is the output of running the code snippet below:
int age= 24;
AGE= 25
if (age< 22) { AGE++; }
age++;
AGE--;
System.out.println(age};
System.out.println{AGE);
[8 Marks]
(4 Marks)
(B) Modify the print statement below to print 2.
int X =2;
int y=-2;
System.out.println( };
(4 Marks)
Question Three
[8 Marks]
Write a Java program to request for an input number from the keyboard and print out Even
if the number is even or Odd if the number is odd. Write a Main program to call the Method
below.
3

4 Page 4

▲back to top


/ /Method starts from here
Public static void findEvenOdd(int num)
{
//method body
if(num%2==0}
{
System.out.println(num+ "is Even");
else
System.out.println(num+"is Old");
SECTION D: CODING/THEORY
Answer ALL questions
Each correct answer to a question is allocated 8 Marks
Question one
[8 Marks]
Write a Java program that computes the areas of 3 circles, given that:
Area= PR2 where P = 3.14, Rfor Radius.
For each circle, the program should accept a number (Radius) as input from the keyboard.
The program should display this as sample output:
Please Enter Radius: 5
Area= 78.5
[Hint: Area= 3.14*5*5=78.5]
Please Enter Radius: 9
Area = 254.34
[Hint: Area= 3.14*9*9=254.34]
Please Enter Radius: 4
Area= 50.24
[Hint: Area= 3.14*4*4=50.24]
Note that the Hint is not part of the output.
Question Two
(8 Marks]
Write a Java program that will ask for two .integer numbers as input from the keyboard and print out
the sum, difference, product, division, square root, comparism of the two numbers and increment of
a third number.
Sample input
Enter the first number: 20
Enter the second number: 10
Sample Output
The sum of the two numbers is: 30.0
The difference of the two numbers is: 10.0
The product of the two numbers is: 200.0
The division of the two numbers is: 2.0
The square root of third number 9 is: 3
First number is bigger than the second number.
Increment of third number 9: 10
4

5 Page 5

▲back to top


Question Three
(8 Marks]
Write a Java program to sum ALL numbers between startNo and end No. You may use either
for statement, While statement, Do while statement or any other control structure
statement in Java. The following should be programmed:
Two numbers (startNo and endNo) should be accepted as input from the keyboard.
(1) If startNo is less than Othen the program should print "startNo cannot be less than O"
and the program will end. (2 Marks)
(2) If endNo is less than Othen the program should print "end No cannot be less than O"and
the program will end. (2 Marks)
(3) If end No is greater than 9 then the program should print "end No cannot be greater than
9" and the program will end. (2 Marks)
(4) But, if the right numbers (startNo and end No) are entered ie any two numbers within 0, 1, 2,
3, 4, 5, 6, 7, 8, 9, then the sum of ALL numbers between startNo and EndNo will be calculated
and the program will printout "Sum of ALL Numbers=" sumALL.
(2 Marks)
Sample output 1:
Input: Enter 2 Numbers separated with a space (startNo and endNo): -3 7
Output: startNo cannot be less than 0
Sample output 2:
Input: Enter 2 Numbers separated with a space (startNo and endNo): 2 -9
Output: end No cannot be less than O
Sample output 3:
Input: Enter 2 Numbers separated with a space (startNo and endNo): 2 20
Output: end No cannot be greater than 9
Sample output 4:
Input: Enter 2 Numbers separated with a space (startNo and endNo): 2 5
Output: Sum of ALL Numbers= 14
[Hint: ALL numbers from 2 to 5 are: 2,3,4,5 therefore Sum= 2+3+4+5=14]
Note: Kindly accept any other reasonable solutions and allocate marks accordingly.
---THE
END
5