You are on page 1of 3

ICS 2201: OBJECT ORIENTED PROGRAMMING II

Group Exercises
Date of Issue:

November 06, 2015

Due Date:

November 20, 2015

Question One
i)

What is purpose of new operator as used in Java?

ii)

Explain the role of static keyword in public static void main (String args[])?

iii)

What is default layout for frame and panel?

iv)

Create a base class called shape. It contain two methods get xy value( ) show xy
value( ) for accept co-ordinates & to display the same. Create a subclass called
rectangle. It also contain a method to display the length & breadth as the rectangle
called show xy value( ) using overriding concept.

Question Two
i)

What are Access modifiers available in Java Programming Language?

ii)

Differentiate between primitive and non primitive data type in Java

iii)

What is the difference between this() and super()?

iv)

Create a class called car. Initialise the colour and the body to blue and wagon
respectively. There should be two constructors. One is the default constructor that
creates a blue wagon. The other constructor should take two arguments (colour and
body).

Question Three
i.

What is an exception? What are their types? Explain how user defined exception
clasess can be created

ii.

List and explain any four methods of the MouseListener interface

iii.

Differentiate between static and dynamic binding

iv.

Create a class employee with data members employee (ID, employee name,
designation and salary) Write methods getEmployee( ) - To take user input,
showGrade( )- to display grade of employee based on salary, showEmployee( ) to
display employee details.

Question Four
a)
b)
c)
d)

What is the difference between static, final, finally and finalize () in Java
Identify and explain the the use of layout managers in Java
What is difference between overriding and overloading a method?
Write a program that has an overloaded method. The first method should accept no
arguments the second method will accept one string & the third method will accept a
string & an integer. The first method should display the message welcome to java
once. The second method should display the message welcome to polymorphism
twice & the third method should display the message welcome to overloading three
times.

Question Five
Sarova Whitesand Hotel in Mombasa 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
5,000.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:
a) Input name of guest, total number of days stayed in the hotel.
b) Calculate the total amount to be paid and the discount amount.
c) Find the net balance to be paid excluding the discount.

Question Six
a) What is the use of the keyword Super in Java
b) Differentiate between a constructor and a method.
c) Define a Student class (roll number, name, percentage). Define a default and
parameterized constructor. Create objects using parameterized constructor and display
the object count after each object is created. (Use static member and method). Also
display the contents of each object.
d) Write a Java application that determines and prints the number of odd, even and zero
digits in the array.

Question Seven
a) Explain the difference between AWT & Swing components
b) Explain the following classes:
i.

JFrame

ii.

JList

iii.

JLable

iv.

JTextField

v.

JTextArea

c) Explain exception handling in Java


d) Create a class Student with attributes roll no, name, age and course. Initialize values
through parameterized constructor. If age of student is not in between 15 and 21 then
generate user-defined exception AgeNotWithinRangeException. If name contains
numbers or special symbols raise exception NameNotValidException. Define the
two exception classes.

You might also like