0% found this document useful (0 votes)
49 views

Comp Programming Ii

This document contains instructions for a Computer Programming II exam to be taken by second year Diploma in Information Technology for Science students at Uganda Institute of Information and Communications Technology. The exam will take place on September 28, 2022 from 2-5 PM and consists of two sections - Section A with 40 marks and Section B with 60 marks. Section A contains 5 compulsory questions while Section B contains 6 questions where students must answer only 3. The questions will test students' knowledge of object-oriented programming concepts in Java including classes, objects, inheritance, polymorphism, abstraction, encapsulation, methods, loops, and more.

Uploaded by

Alex Nsubuga
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

Comp Programming Ii

This document contains instructions for a Computer Programming II exam to be taken by second year Diploma in Information Technology for Science students at Uganda Institute of Information and Communications Technology. The exam will take place on September 28, 2022 from 2-5 PM and consists of two sections - Section A with 40 marks and Section B with 60 marks. Section A contains 5 compulsory questions while Section B contains 6 questions where students must answer only 3. The questions will test students' knowledge of object-oriented programming concepts in Java including classes, objects, inheritance, polymorphism, abstraction, encapsulation, methods, loops, and more.

Uploaded by

Alex Nsubuga
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

COMPUTER PROGRAMMING II

UGANDA INSTITUTE OF INFORMATION AND


COMMUNICATIONS TECHNOLOGY
RECESS EXAMINATIONS FOR ACADEMIC YEAR
2021/2022
DEPARTMENT: ICT

SEMESTER: ONE

PROGRAMME(S): DIPLOMA IN INFORMATION TECHNOLOGY


FOR SCIENCE (DITS)

YEAR OF STUDY: TWO

COURSE: COMPUTER PROGRAMMING II

COURSE CODE : IT211

DATE: WEDNESDAY 28TH, SEPTEMBER 2022

TIME: 2:00 PM – 5:00 PM

DURATION: 3 HOURS

INSTRUCTIONS:

(i) This paper contains two Sections: A (40 marks) & B (60 marks).
(ii) Attempt ALL questions in Section A, and ONLY THREE questions in
Section B.
(iii) All questions in Section B carry equal marks.
COMPUTER PROGRAMMING II

(iv) Credit will be given for use of relevant examples and illustrations.
(v) Begin each number in Section B on a new page of the answer sheet.
(vi) DO NOT write on this question paper.
COMPUTER PROGRAMMING II

SECTION A [40 MARKS]

Attempt ALL the Questions in this section

Question 1

1. Distinguish the following terms as used in Java Programming:


a) Derived class and base class (4 marks)
b) Object and class (4 marks)

2. Explain the meaning of the following as used in Object Oriented Programming.


a) Inheritance (2 marks)
b) Polymorphism (2 marks)
c) Abstraction of data (2 marks)
d) Encapsulation (2 marks)

3. a) Give the syntax for the while loop and explain its semantics. (2 marks)
b) Given the program below:

public class MyClass{
  int  i = 30;
int j = 12;
public static void main(String[]args){
   MyClass myObj1 = new MyClass();  
     MyClass myObj2 = new MyClass();  
     System.out.println(myObj1.i);
     System.out.println(myObj2.j);
 }
}

State the purpose of the following codes as used in the above program:
i) MyClass myObj1 = new MyClass(); (2 marks)
ii) System.out.println(myObj2.j); (2 marks)
iii) public class MyClass (2 marks)

4. a) Java methods make the language easy to use.


Explain the meaning of the term method as used in Java programming.
(2
marks)
b) Distinguish method overriding from method overloading. (4 marks)
c) List any two key words used in a method header. (2 marks)
COMPUTER PROGRAMMING II

5. Java programming language is popular because of its characteristics. List and


explain any four characteristics of java. (8 marks)
SECTION B [60 MARKS]

Attempt ONLY THREE Questions in this section

Question 2

Study the following piece of java code and answer questions that follow:
public class SquareMain {
public static void main(String[] args) {
int result, n;
n = 3;
answer = square(n);
System.out.println("Square of 3 is: " + answer);
}
static int square(int i) {
return i * i;
}
}

a) Identify and correct the error(s) in the above program. (3 marks)


b) A method cannot be used until it is defined and called.
i) Write down the correct syntax for calling a method. (2 marks)
ii) State the code where a method is being called in the program above.
(2
marks)
iii) Write down the code(s) for method definition in the program above and
hence state the purpose of the program. (3 marks)
c) Write a java program used to capture user input for two integers and display the
product. (10 marks)

Question 3
a) Explain the meaning of the following access specifiers:
i) public (2 marks)
ii) private (2 marks)
iii) protected (2 marks)
b) Distinguish the concept of single inheritance from multiple inheritance as used in
Java programming. (4 marks)
c) The quadratic equation , can be solved using the formula:
x = (-b + √(b2 – 4ac))/2a   
COMPUTER PROGRAMMING II

Write a java program which can prompt the user to input values of a, b and c, and
to calculate and display the values of only where there exists real roots to the
equation. (10 marks)

Question 4
Study the flow chart below and use it to answer questions about it.

START

SUM = 0

N=0

N=N+1

SUM = SUM + N

YES
NO
IS N=10?

PRINT SUM

END

(a) Write a Java program used to implement the flow chart above (10 marks)

(b) Write a Java program used to grade soap detergents depending on weight in
grams as follows:

Weight (Grams) Category


Between 700 and 1000 BIG
From 500 to 699 MEDIUM
Below 500 SMALL (10 marks)

Question 5
COMPUTER PROGRAMMING II

a) Kalere sat three courses last semester and the average mark was used by his
sponsor to determine whether to fund his last semester only if the average is
greater or equal to 70 marks. Each course was marked out of 100 marks. Using
a while loop to compute total marks Kalere scored, write a program the sponsor
would use to determine Kalere’s sponsorship in the last semester.
(10 marks)

b) Carefully study the codes below and answer questions that follow:
public class WelcomeUICT
{
public static void main(String[ ] args)
{
System.out.println("Welcome to UICT Java Laboratory!");
System.exit(0);
}
}
(i) State the name of the class in the above codes (2 marks)
(ii) Write down the class header in the codes above. (2 marks)
(iii) Which class is used to give output of the above code. (2 marks)
(iv) Give the name of the type of methods used in the above code.
(2
marks)
(v) Explain the use of the key word “Static” in the program. (2 marks)

Question 6

a) Explain the difference between the for loop and do while loop in terms of
syntax and semantics. (4 marks)
b) Distinguish between a local variable and a global variable (2 marks)
c) State any four rules used in naming valid Java identifiers (4 marks)
d) Given the program below, re-write it using If – Else control structure.
(10
marks)
import java.util.Scanner;
public class CalculatorUsingSwitch {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter value of 1st number ::");
COMPUTER PROGRAMMING II

int a = sc.nextInt();
System.out.println("Enter value of 2nd number ::");
int b = sc.nextInt();
System.out.println("Select operation");
System.out.println("Addition-a: Subtraction-s: Multiplication-m: Division-d: ");
char ch = sc.next().charAt(0);
switch(ch) {
if (ch== 'a')
{
System.out.println("Sum of the given two numbers: "+(a+b));
}
else if (ch== 's')
{
System.out.println("Difference between the two numbers: "+(a-b));
}
else if(ch== 'm')
{
System.out.println("Product of the two numbers: "+(a*b));
}
else if (ch=='d')
{
System.out.println("Result of the division: "+(a/b));
}
else
{
System.out.println("PLEASE ENTER CORRECT VALUE!");
}
}
}

END

You might also like