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

java 3

The document outlines the examination details for a Java Programming course, including instructions for answering questions and the structure of the exam. It consists of four questions covering various Java programming concepts, including method overloading, constructors, and object-oriented programming principles. Students are required to write Java programs and explain concepts in their answers, with specific marks allocated to each question.

Uploaded by

GDE The third
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

java 3

The document outlines the examination details for a Java Programming course, including instructions for answering questions and the structure of the exam. It consists of four questions covering various Java programming concepts, including method overloading, constructors, and object-oriented programming principles. Students are required to write Java programs and explain concepts in their answers, with specific marks allocated to each question.

Uploaded by

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

UNIVERSITY EXAMINATIONS: 2023/2024

EXAMINATION FOR DEGREE IN BACHELOR OF SCIENCE IN


INFORMATION TECHNOLOGY/ BUSINESS I.T/APPLIED
COMPUTING/ SOFTWARE DEV./INFO. SECURITY& FORENSICS
BIT 2204A/ BBIT 310 /BAC 2201/ BSD 2107/BISF 2201:
JAVA PROGRAMMING
PART TIME/FULL TIME/DISTANCE LEARNING
ORDINARY EXAMINATION
DATE: AUGUST, 2024 TIME: 2 HOURS
INSTRUCTIONS: Question One Is Compulsory, Choose Two Other Questions
QUESTION ONE (20 marks) Compulsory
a) When you compile a program written in the Java programming language, the compiler
converts the human-readable source file into platform-independent code that a Java Virtual
Machine can understand. What is this platform-independent code called? Explain why this
is necessary. (3marks)
b) Explain the part of the main method “public static void main (string []args)” (4marks)
c) Differentiate between method overloading and method overriding. (2marks)
d) State the main difference between the following terms used in Object Oriented
Programming
i. Object and classes (2marks)
ii. Encapsulation and data abstraction (2marks)
e) What are constructors? Giving an example, show why they are useful in java programming
(3marks)
f) Write a Java program which allow the user to input four integers it then output the
maximum of the four integers. (4marks)

QUESTION TWO (15 marks)


a) Write a java application that prints, on separate lines, you name, your birthday, your
hobbies and your favourites books. Label each piece of information in the output.
(5marks)
b) Write a Java program to input the price and quantity purchased of an item. The program
them computes the discount and the total amount to be paid. Assume a discount of 6%
(5marks)
c) Write a program that prompts the user for the radius and height of a solid cylinder.
Integrate into the program the functions find_SArea( ) and find_Vol( ) which respectively
calculates the total surface area and volume of the cylinder and returns their result to the
caller for display. Include an exception to trap negative value radius and height with
appropriate error messages. (5marks)

QUESTION THREE (15 marks)


a) A hotel is giving seasonal discount on the total amount to be paid by the person staying at
the time of check out. The charge for one day stay is Kshs 850.00 per room. The discount
will be given as per the following criteria:
Number of days stayed Discount on total amount
Up to 5 days 10 %
> 5 days and < = 10 days 15 %
> 10 days and < = 20 days 20 %
More than 20 days 25 %
Required:
Write a java program that will:
i. Input name of guest, total number of days stayed in the hotel. (4marks)
ii. Calculate the total amount to be paid and the discount amount. (6marks)
iii. Find the net balance to be paid excluding the discount. (5marks)

QUESTION FOUR (15 marks)


a) Describe what is meant by the term method over riding and comment on the importance of
method signatures in determining which method is overridden. Illustrate method overriding
with code written in java. (5marks)
b) Use the java code below to answer the questions that follow.
class atomClass
{
private:
int protons;
int neutrons;
int electrons;
protected:
static int electronCharge;
public:
atomClass();
atomClass(int p, int n, int e);
void setProtons(int p);
int getNeutrons();
};
i). If we wished to publically inherit from atom Class, explain which members would
be visible in the derived class, and state their designation. (3marks)
ii). Explain the purpose of a copy constructor, and propose how one might be
implemented for atomClass, assuming that we had a full suite of accessor functions.
(2marks)
c) Write the output of the following java inheritance code (3marks)
Class A{
Public void fun (ints){
system.out. println(“int in A is:”+x);
}
}

Class B extends A{
Public void funz (int x, inty){
fun (6)
system.out. println(“int in B is:”+x” and “+
y);
}
}

public class inherit {


public static void main (string [] args){
B obj=newB();
obj.funz(2,5);
}
}
d) Explain the difference between the outputs from program statements in I and II below.
(2marks)
I. String s;
System.out.println("s = " + s);
II. String s = new String();
System.out.println("s = " + s);

You might also like