UNIVERSITY EXAMINATIONS: 2013/2014
ORDINARY EXAMINATION FOR THE BACHELOR OF SCIENCE
IN INFORMATION TECHNOLOGY
BIT 2204A JAVA PROGRAMMING
DATE: APRIL, 2014 TIME: 2 HOURS
INSTRUCTIONS: Answer Question ONE and any other TWO
QUESTION ONE
a) Explain the following terms as used in Java programming:
i). Package
ii). Method
iii). Interface
[6 Marks]
b) Write a Java application program that inputs two integer numbers using Input box
dialogs and then computes and displays the sum and average using a message box
dialog
[5 Marks]
c) Write a java program that has a class called circle from which two circles, c1 and c2
are created in such way that c2 does not pass any argument to the constructor yet its
radius value is initialized to 10 and c1 is instantiated with the value 20. The class
should have a method to calculate the area of the two circles which should then be
displayed in an appropriate format. [7 Marks]
d) Write Java programs to generate and display numbers one to ten in the console
window, using:
i). for loop
ii). do…while loop
[6 Marks]
e) Write a Java program that uses an applet to generate and display the word “Welcome
to Java Programming” five times in the center of the applet as shown below:
[6 Marks]
QUESTION TWO
a) Distinguish between method Overloading and method Overriding
[2 Marks]
b) Write a program that calculates the area of a circle, rectangle and square using
overloaded versions of a method area (). Use the console window for inputs and
outputs using the main method.
[6 Marks]
c) In a given hospital, patients are required to register upon arrival. The details taken
include their name, gender and year of birth. Patients aged between 0 to 12 years
should consult a pediatrician, otherwise they consult a physician. The patient is then
issued with a prescription stating the drugs to be given and the amount to be paid. A
system to be used in the hospital is required. The system should be able to give the
details of the patient, the doctor to be consulted and prescription with cost.
Required: Write a Java application program to be used by the hospital
[12 Marks]
QUESTION THREE
a) Differentiate between extends and implements as used in java programming.
[2 Marks]
b) Write a Java program to determine the area of rectangle and square. The program
should consist of an abstract class and two other classes for finding the area of square
and rectangle. All classes uses constructors to initialize the data members and have a
method Area (), which is used to calculate and display the area of the respective
shapes.
[10 Marks]
c) Write a Java program that prompts and reads ten integer numbers into an array. Your
program then determines and displays the largest number, smallest number, sum and
average of the numbers.
[8 Marks]
QUESTION FOUR
a) Using a diagram, explain the four applet methods that correspond to the four types of
reactions of an applet life cycle.
[10 Marks]
b) Write a complete Java Applet that converts Celsius temperatures in the range 0-100,
with a step size of 20 (i.e. 0, 20, 40, etc.) to the equivalent Fahrenheit temperatures
and displays the results in a text area box. The formula for conversion is:
fahrenheit=(9.0/5.0)*celsius+32;
[10 Marks]
QUESTION FIVE
a) Explain any two major differences between applets and applications
[4 Marks]
b) Explain briefly how Java programs implement event driven programming
capabilities in GUI based programs
[6 Marks]
c) Write a program to convert temperature from Fahrenheit to Celsius. Your program
should have an interface similar to the one shown below.
[10 Marks]