You are on page 1of 5

Object Oriented Programming

Objective:
Write several Java classes that utilize inheritance

The Problem:
In this assignment you will use inheritance to simplify the development of an information system
for a company.

Before you start this assignment, create a new project in your workspace using Eclipse. All
solution files for this assignment should be placed in this project.
Project must compile without error. If your program does not compile, you will lose 50% of the
points

A part of the class diagram is given below.

Person

Customer Employee

FullTimeEmployee PartTimeEmployee

(1) Create the class Person that includes attributes: id, name, age, and gender with data types:
“int”, “String”, “int”, and “char” respectively.

(2) Include a constructor in the class Person with parameters: id, name, age, and gender.

(3) Include getters and setters for each attribute of the class Person.

(4) Include a method called display to the class Person to display the values of attributes of the class.
(5) Include a static method called calculateAverageAge to the class Person to get the average age of a
list of persons.

(6) Create the class Customer that includes attributes: level, amount1, amount2, and profit with data
types: “int”, “double”, “double”, and “double” respectively.

(7) Include a constructor to the class Customer with parameters: id, name, age, gender, and level.

(8) Include getters and setters for each attribute of the class Customer.

1
(9) Include a method called display to the class Customer to display the values of attributes of the
class.

(10) Consider the class Customer. The value of the attribute profit is computed by subtracting the value
of the attribute amount1 from the value of the attribute amount2. Include a method called
calculateProfit to the class to calculate the value of the attribute profit.

(11) Include a method called buyItems to the class Customer with parameters: price1, price2, and n.
The new value of the attribute amount1 is computed by multiplying the value of the attribute price1
with the value of the attribute n and adding the value of the attribute amount1. The value of the
attribute amount2 is computed by multiplying the value of the attribute price2 with the value of the
attribute n and adding the value of the attribute amount2. Include these computations to the body of
the method.

(12) Create the driver class called Test that includes the “main” method.

(13) Include a class method called display to the class Test that takes an array of references of type
Person as the parameter. The method should display the values of attributes of the objects referred
through the parameter.

(14) Create an array that holds five Customer objects. Assign the objects given in the table below to each
array element using the constructor.

id nameage gende level


r
3521 Rami 27 M 3
4863 Nabil 23 M 2
5791 Nariman 28 F 4
2456 Chadi 32 M 1
7593 Wafaa 18 F 2

(15) Use the method display in the class Test to display the values of attributes of the Customer objects.
(16) Increment the value of the attribute level of the fourth Customer object by 1.
(17) Use the method display in the class Customer to display the values of attributes of second
and third Customer objects.
(18) Use the method calculateAverageAge in the class Person to compute the average age of the
Customer objects.

(19) The table given below shows the set of items bought by each of the customer. Use the method

2
buyItems in the class Customer to add the given items.

id price1 price2 n
3521 54 57 8
32 39 5
75 76 7
4863 45 48 9
78 81 12
12 14 17
24 27 4
5791 92 96 8
125 130 10
2456 82 89 7
138 155 6
52 60 2
66 75 11
105 120 21
7593 99 110 2

(20) Use the method calculateProfit in the class Customer to compute the value of the attribute
profit of each Customer object.

(21) Display the value of the attribute profit of each Customer object.

(22) Create the class Employee that includes attributes: designation, mobile, salary and tax with data
types: “String”, “String”, “double” and “double” respectively.

(23) Include a constructor to the class Employee with parameters: id, name, age, gender,
designation, and mobile.

(24) Include getters and setters for each attribute of the class Employee.

(25) Include a method called display to the class Employee to display the values of attributes of the
class.

(26) Include a method called computeTax to the class Employee with the parameter taxRate to compute
the value of the attribute tax. The value of the attribute tax is computed by multiplying the value of
the attribute salary with the value of the attribute taxRate.

(27) Include a method called getNetSalary to the class Employee. The method should return the value
that is computed by subtracting the value of the attribute tax from the value of the attribute salary.

(28) Create the class FullTimeEmployee that includes attributes: fund and fundRate with data types:
“double” and “double” respectively.

(29) Include a constructor to the class FullTimeEmployee with parameters: id, name, age, gender,
designation, mobile, and fundRate. The value of the attribute fund should be initially zero for any
full-time employee.

3
(30) Include getters and setters for each attribute of the class FullTimeEmployee.

(31) Include a method called display to the class FullTimeEmployee to display the values of attributes
of the class.

(32) Include a method called addToFund to the class FullTimeEmployee to add an amount to the value
of the attribute fund. The amount to be added is computed by multiplying the value of the attribute
salary with the value of the attribute fundRate. The value of the attribute fund should be subtracted
from the value of the attribute salary.

(33) Create an array that holds 3 FullTimeEmployee objects. Assign the objects given in the table below
to each array element using the constructor.

id name age gende designation mobile fundRat


r e
68494 Nada 52 F Manager 05168546 3%
98451 Karim 29 M Assistant 03957634 2%
Manager
79563 Nadin 34 F Clerk 70705025 1%

(34) Use the method display in the class Test to display the values of attributes of the
FullTimeEmployee objects.

(35) Create the class PartTimeEmployee that includes attributes: hours and rate with data types:
“double” and “double” respectively.

(36) Include a constructor to the class PartTimeEmployee with parameters: id, name, age, gender,
designation, mobile, and rate.

(37) Include getters and setters for each attribute of the class PartTimeEmployee.

(38) Include a method called display to the class PartTimeEmployee to display the values of attributes
of the class.

(39) Include a method called computeSalary to the class PartTimeEmployee to compute the value of
the attribute salary. The value of the attribute salary is computed by multiplying the value of the
attribute hours with the value of the attribute rate.

(40) Create an array that holds two PartTimeEmployee objects. Assign the objects given in the table
below to each array element using the constructor.

id name age gende designation mobile rate


r
68542 Samir 56 M Temporary Clerk 01123456 300
79546 Nada 57 F Temporary 05456789 150
Laborer

4
(41) Create an array of type Employee that has 5 elements. Assign the 3 FullTimeEmployee objects and
the two PartTimeEmployee objects you have created to each array element.

(42) Invoke the method computeTax in the class Employee for each Employee object to compute the
value of the attribute tax. Suppose that the value of the parameter taxRate is 0.03.

(43) Update the value of the attribute salary of each Employee object using the method
getNetSalary of the class Employee.

You might also like