BIT2204A BBIT JAVA PROGRAMMING.

UNIVERSITY EXAMINATIONS: 2017/2018
EXAMINATION FOR THE DEGREES OF BACHELOR OF SCIENCE
IN INFORMATION TECHNOLOGY/ BACHELOR OF BUSINESS IN
INFORMATION TECHNOLOGY
BIT 2204A/ BBIT: JAVA PROGRAMMING
FULLTIME/ PART TIME/DISTANCE LEARNING
ORDINARY EXAMINATIONS
DATE: NOVEMBER, 2017 TIME: 2 HOURS
INSTRUCTIONS: Answer Question One & ANY OTHER TWO questions.

QUESTION ONE
a) Briefly explain the meaning of the following terms and write Java code that demonstrates
its usage. [6 Marks]
i) Global Variable
ii) Static Method
iii) Class
b) Write a java class that compares two integers to determine which one larger is. Results are
then printed [4 Marks]
c) Write For-loop structure using a well commented java programming code that can print the
following four names [4 Marks]
tom,kim,james,peter
d) Write a do-while loop structure using a well commented java programming language that
can print a menu with the following list of items. comment the code [4 Marks]
Degree Programs offered in FOCIM.
1. Bsc IT
2. Bsc Applied Computing
3. Bachelor of Business IT
4. Bsc ICT
4. Exit
e) Write a class named Rectangle that instantiates Rectangle1 object from the class you
created. Prompt the a user to enter width and length, calculates perimeter and then displays
results [6 Marks]
(f) Briefly explain the meaning of the following concepts and write a java code that
demonstrates how they can be implemented [6 Marks]
i) Parameters
ii) Object
iii) Calling a method
QUESTION TWO
a) Briefly explain the meaning of the following terms in the context of java programming.
Write java code snippet that demonstrates implementation of each case. [4 Marks]
i). Array
ii) inheritance
b). Briefly explain the following java code including its output [5 Marks]
public class Tester
{
static void test(int[] a)
{
int[] b = new int[2];
a = b;
System.out.print(b.length);
System.out.print(a.length);
}
public static void main(String[] args)
{
int[] a = new int[5];
test(a);
System.out.print(a.length);
}}
(c) Write a java class that reads and prints the values of the following array. [5 Marks]
30 82 71 65
(d) Write a Java program to print the result of the following operation [3 Marks]
-5 + 8 * 6
(e) Write a Java program that takes two numbers as input and display the product of two
numbers. [3 Marks]
QUESTION THREE
(a) Write a Java program to print ‘Hello’ on screen and then print your name on a separate
line. For instance it can print the following Output: [3 Marks]
Hello
Alexandra Abramov
(b)Given that One inch is 0.0254 meter, write a Java program that reads a number in inches,
converts it to meters. [3 Marks]
(c) Categorize each of the following quantities by whether an int or double variable would
best to store it: [5 Marks]
(i) Temperature in degrees Celsius
(ii) The population of students
(iii) A person’s age in years
(iv) A person’s weight in pounds
(v) A person’s height in meters
e) Describe the key word ‘import’ as used in java. Write a single line java code illustrating
how ‘import’ can be used in java programming [2 Marks]
f) Describe the following scope qualifiers as used in java programming
i. public [1 Mark]
ii. private [1 Mark]
iii) protected [1 Mark]
a) Write a java class that performs the following tasks: [4 Marks]
i) Request user to enter the price of any two products (e.g. price of milk, price of bread).
ii) Calculates total cost
iii) calculates deducts discount of 5%
iv) prints the amount to be paid by customer
QUESTION FOUR
(a) Describe three properties of a constructor. Write a sample java code to illustrate how it is
implemented in java programming [4 Marks]
(b) Write a java class that performs the following tasks [8 Marks]
i) Requests user to enter Marks for the following assignments
assignment1, assigment2
ii) Compute the sum and average of the two assignments
iii) Determines whether the Pass mark of 5 has been reached given that each
assignment is marked out of 5 Marks.
iv) Display results that include Marks entered for each assignment and whether it is a
pass or fail.
d) Write a Java program to convert days into number of weeks. [3 Marks]
Test Data
Input the number of days: 21
Expected Output :
3 weeks
c) Write a java class that named booking that Prompt the a user to enter ticket details such as
idno, name, destination and then display all the values entered by the user [5 Marks]
QUESTION FIVE
(a) Write Java methods to calculate the area of a triangle and prints results [3 Marks]
(b) State and explain three types of programming errors in java programming. Give one
example in each case [6 Marks]
(c) Describe the term ‘exception ‘ as used in java programming language [2 Marks]
(d) Describe two types of exceptions in the context of java programming [2 Marks]
(e) Consider the following java code instructions and explain the purpose of the single line
statements appearing in bold. [4 Marks]
private static void createAndShowGUI()
{
JFrame frame = new JFrame(“Hi..”);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel label = new JLabel(” Welcome to KCA University”);
frame.getContentPane().add(label);
frame.pack();
frame.setVisible(true); }
d) Briefly explain importance of using ‘LayoutManager’ when developing programs using
swing with graphical interface. Give one example of a layout manager [3 Marks]

(Visited 126 times, 1 visits today)
Share this:

Written by