0% found this document useful (0 votes)
134 views5 pages

Cse 4102 - Object Oriented Programming Supp

This document contains instructions and questions for an object oriented programming exam. It is divided into 5 questions, each worth a different number of marks. Question 1 has 7 sub-questions related to programming concepts like loops, switch statements, and arrays. Question 2 focuses on pattern printing, recursion, and numeric operations. Question 3 covers conditional statements, flowcharts, and methods. Question 4 is about method overloading, recursion, arrays, and passing arrays to functions. Question 5 deals with enumerations, class inheritance, and class relationships. Students are instructed to attempt Question 1 and any other two questions in their answer booklet.

Uploaded by

Victor Ogai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
134 views5 pages

Cse 4102 - Object Oriented Programming Supp

This document contains instructions and questions for an object oriented programming exam. It is divided into 5 questions, each worth a different number of marks. Question 1 has 7 sub-questions related to programming concepts like loops, switch statements, and arrays. Question 2 focuses on pattern printing, recursion, and numeric operations. Question 3 covers conditional statements, flowcharts, and methods. Question 4 is about method overloading, recursion, arrays, and passing arrays to functions. Question 5 deals with enumerations, class inheritance, and class relationships. Students are instructed to attempt Question 1 and any other two questions in their answer booklet.

Uploaded by

Victor Ogai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

TECHNICAL UNIVERSITY OF MOMBASA

SCHOOL OF BUSINESS
DEPARTMENT OF MANAGEMENT SCIENCE

UNIVERSITY EXAMINATION FOR:


BACHELOR OF BUSINESS INFORMATION TECHNOLOGY
CSE 4102: OBJECT ORIENTED PROGRAMMING

END OF SEMESTER EXAMINATION


ORDINARY EXAMINATIONS
SERIES: DECEMBER 2023
TIME: TWO HOURS
DATE: DECEMBER 2023
Instructions to Candidates
You should have the following for this examination
-Answer Booklet, examination pass and student ID
This paper consists FIVE questions. Attempt Question ONE and Any other TWO
Questions.
Do not write on the question paper.

QUESTION ONE [30 MARKS]

a) What is the difference between a for loop and a while loop? (2 Marks)

b) How many times does a do-while loop execute? (2 Mark)

c) Write a Java program that accepts a character input from the user and determines
whether it is a digit or a non-digit character using a switch statement. (4 Marks)

d) Write a program in Java to prompt the user to enter the length and radius of an open
cylinder and then calculate and print its surface area and volume. (5 Marks)

e) What will be the output of the following computation based on the following?
(4 Marks)

Let x=7, y=6, z=3


i (x< =y)| | (y!=x)
ii (y%x)<=x
iii (z%x)<=(y%x
iv z=++y++-x++

f) Write a Java program that prompts the user to input 10 integers, stores them in an
array, and then prints the average of the values. (5 Marks)

g) Write a Java program that reads data from an input file called "input.txt" and writes the
data to two output files called "odd.txt" and "even.txt". The input file contains a list of
numbers, one number per line, and the output files should contain the odd and even
numbers, respectively. (5 Marks)

QUESTION TWO [20 MARKS]

a) Write a Java program, squareOfAsterisks that displays a pattern of asterisks, whose


side is specified in integer parameter side. For example, if side is 4, the method should
display. (5 Marks)
1
33
555
7777

b) Write a Java program that defines a function called "factorial" that takes an integer as an
argument and returns its factorial. (5 Marks)

c) Write a Java program to calculate the sum of odd numbers from 1 to 100 using a while
loop (5 Marks)

d) Explain the following concepts (5 Marks)


i. Encapsulation
ii. Abstraction
iii. Modularity
iv. Coupling
v. Polymorphism

QUESTION THREE [20 MARKS]

a) Write a Java program that prompts the user to enter a number between 1 and 7 and
prints the corresponding day of the week (1 = Monday, 2 = Tuesday, etc.) (5 marks)

b) Distinguish between the operation of a while loop and a do while. Use a flowchart to
explain (4 Marks)

c) Write a program that assigns a grade to a score such that if the score is between 75 and
100 the grade is A, a score between 64 to 75, the grade is B. The score between 50 and 65

BCS 210/BIT 210: OBJECT ORIENTED PROGRAMMING II 2


is a C and anything below is assigned grade F. The program should display the score
prompted and the grade assigned. (8 Marks)

d) Explain the use of the following key words using an example (3 Marks)
i. this
ii. final
iii. implements

QUESTION FOUR [20 MARKS]

a) What is method overloading in Java? (2 Marks)

b) What is recursion in Java Classes? (2 Marks)

c) Write a Java program that defines a function called "maxValue" that takes an array of
integers and its length as arguments and returns the maximum value in the array.
(5 Marks)

d) How do you find the length of an array in Java. Use an example? (2 Mark)

a) What is a two-dimensional array in Java? How is it declared and initialized? (2 Marks)

b) How do you pass an array as an argument to a function in Java? (2 Marks)

c) Write a program that is able to compute the factorial of a number using a method
factorial( int x)

(5 Marks)

QUESTION FIVE [20 MARKS]

a) Write a Java program that defines an enumeration data type called "Month" that
represents the months of the year (January through December), and an array of strings
called "monthNames" that stores the names of the months. The program should then
prompt the user to enter a month number (starting from 1 for January) and display the
corresponding month name. (5 Marks]

BCS 210/BIT 210: OBJECT ORIENTED PROGRAMMING II 3


b) Consider the definition of the class C shown below.
public class C
{
int m;
int n;
public C(int mIn, int nIn)
{
m = mIn;
n = nIn;
}
public int m1()
{
return m+n;
}
}
Define a subclass of C named B that overrides method m1() so that it returns the
difference between m and n instead of their sum. Provide the appropriate access
modifier for the instance variables m and n. [5 Marks]
e) Given the classes with the following headers
public class Animal ...
public class DomesticAnimal extends Animal ...
public class FarmAnimal extends DomesticAnimal...
public class HousePet extends DomesticAnimal...
public class Cow extends FarmAnimal ...
public class Goat extends FarmAnimal ...
public class DairyCow extends Cow ...
draw a class diagram representing the hierarchy created by these declarations.
[2 marks]

BCS 210/BIT 210: OBJECT ORIENTED PROGRAMMING II 4


f) Given the preceding hierarchy of classes, state with reasons why the following
assignments are correct/wrong. [3 marks]
DairyCow dc = new FarmAnimal();
FarmAnimal fa = new Goat();
Cow c1 = new DomesticAnimal();
Cow c2 = new DairyCow();
DomesticAnimal dom = new HousePet();

BCS 210/BIT 210: OBJECT ORIENTED PROGRAMMING II 5

You might also like