SlideShare a Scribd company logo
Object Oriented Programming in Java [Lesson 1; Lesson 2; Lesson 3; Lesson 4]
1 of 6
Object Oriented Programming Assignment 4
Author: Kasun Ranga Wijeweera
Email: krw19870829@gmail.com
Date: 2019 October 25
1) Suppose you have to develop an information system for a company. A part of the class
diagram is given below.
a) Create the class Person that includes attributes: id, name, age, and gender with data
types: “int”, “String”, “int”, and “char” respectively.
b) Include a constructor to the class Person with parameters: id, name, age, and gender.
c) Include getters and setters for each attribute of the class Person.
d) Include a method called display to the class Person to display the values of attributes of
the class.
e) Include a method called getAverageAge to the class Person to get the average age of a
person.
f) Create the class Customer that includes attributes: level, amount1, amount2, and profit
with data types: “int”, “double”, “double”, and “double” respectively.
g) Include a constructor to the class Customer with parameters: id, name, age, gender, and
level.
h) Include getters and setters for each attribute of the class Customer.
i) Include a method called display to the class Customer to display the values of attributes
of the class.
Person
Customer Employee
FullTimeEmployee PartTimeEmployee
Object Oriented Programming in Java [Lesson 1; Lesson 2; Lesson 3; Lesson 4]
2 of 6
j) 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.
k) 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.
l) Include a method called reduceProfit to the class Customer that computes the value of
reduction. The value of reduction is computed by multiplying the value of attribute profit
from the value of t. The value of t is based on the value of the attribute level as given in
the table below. Furthermore, the value of reduction should be subtracted from the value
of attribute profit.
level t
1 0.03
2 0.05
3 0.08
4 0.12
m) Create the driver class called Test that includes the “main” method.
n) 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.
o) Create an array that holds five Customer objects. Assign the objects given in the table
below to each array element using the constructor.
id name age gender level
3521 Kasun 27 M 3
4863 Nimal 23 M 2
5791 Nayana 28 F 4
2456 Chathura 32 M 1
7593 Waruni 18 F 2
p) Use the method display in the class Test to display the values of attributes of the
Customer objects.
q) Increment the value of the attribute level of the fourth Customer object by 1.
Object Oriented Programming in Java [Lesson 1; Lesson 2; Lesson 3; Lesson 4]
3 of 6
r) Change the value of the attribute gender of the third Customer object to „M‟.
s) Use the method display in the class Customer to display the values of attributes of
second and third Customer objects.
t) Use the method getAverageAge in the class Person to compute the average age of the
Customer objects.
u) The table given below shows the set of items bought by each of the customer. Use the
method 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
v) Use the method calculateProfit in the class Customer to compute the value of the
attribute profit of each Customer object.
w) Display the value of the attribute profit of each Customer object.
x) Compute the new value of the attribute profit of each Customer object using the method
reduceProfit in the class Customer.
y) Create the class Employee that includes attributes: designation, mobile, salary and tax
with data types: “String”, “String”, “double” and “double” respectively.
z) Include a constructor to the class Employee with parameters: id, name, age, gender,
designation, and mobile.
aa) Include getters and setters for each attribute of the class Employee.
Object Oriented Programming in Java [Lesson 1; Lesson 2; Lesson 3; Lesson 4]
4 of 6
bb) Include a method called display to the class Employee to display the values of attributes
of the class.
cc) Include a method called getAverageSalary to the class Employee to get the average
salary of an employee.
dd) 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.
ee) 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.
ff) Create the class FullTimeEmployee that includes attributes: fund and fundRate with
data types: “double” and “double” respectively.
gg) 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.
hh) Include getters and setters for each attribute of the class FullTimeEmployee.
ii) Include a method called display to the class FullTimeEmployee to display the values of
attributes of the class.
jj) 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.
kk) Create an array that holds seven FullTimeEmployee objects. Assign the objects given in
the table below to each array element using the constructor.
id name age gender designation mobile fundRate
68494 Nuwan 52 M Manager 0516859465 3%
98451 Charaka 29 M Assistant Manager 0919576348 2%
79563 Wathsala 34 F Clerk 0668567956 1%
36864 Chathurika 35 F Clerk 0219762354 2%
48952 Sandun 27 M Laborer 0319548261 1%
65825 Janith 21 M Laborer 0119652352 0.5%
56286 Chamari 38 F Clerk 0512648927 2%
Object Oriented Programming in Java [Lesson 1; Lesson 2; Lesson 3; Lesson 4]
5 of 6
ll) Use the method display in the class Test to display the values of attributes of the
FullTimeEmployee objects.
mm) Set the value of the attribute salary of each FullTimeEmployee object according
to the table given below.
id salary
68494 65000
98451 60000
79563 35000
36864 30000
48952 20000
65825 25000
56286 40000
nn) Invoke the method addToFund in the class FullTimeEmployee for each
FullTimeEmployee object. The value of the parameter fundRate is computed according
to the table given below.
id fundRate
68494 4%
98451 3%
79563 2%
36864 1%
48952 2%
65825 2%
56286 1%
oo) Create the class PartTimeEmployee that includes attributes: hours and rate with data
types: “double” and “double” respectively.
pp) Include a constructor to the class PartTimeEmployee with parameters: id, name, age,
gender, designation, mobile, and rate.
qq) Include getters and setters for each attribute of the class PartTimeEmployee.
rr) Include a method called display to the class PartTimeEmployee to display the values of
attributes of the class.
ss) 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.
Object Oriented Programming in Java [Lesson 1; Lesson 2; Lesson 3; Lesson 4]
6 of 6
tt) 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 gender designation mobile rate
68542 Saman 56 M Temporary Clerk 0215698542 300
79546 Nimal 57 M Temporary Laborer 081684952 150
uu) Set the value of the attribute hours of each PartTimeEmployee object according to the
table given below.
id hours
68542 160
79546 172
vv) Compute the value of the attribute salary of each PartTimeEmployee object by
invoking the method computeSalary in the class PartTimeEmployee.
ww) Create an array of type Employee that has nine elements. Assign the seven
FullTimeEmployee objects and the two PartTimeEmployee objects you have created to
each array element.
xx) 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.
yy) Update the value of the attribute salary of each Employee object using the method
getNetSalary of the class Employee.
zz) Invoke the method getAverageSalary in the class Employee to compute the average
salary of each Employee object.

More Related Content

What's hot

3.2 stacks and arrays
3.2   stacks and arrays3.2   stacks and arrays
3.2 stacks and arraysallenbailey
 
Comp 328 final guide
Comp 328 final guideComp 328 final guide
Comp 328 final guide
krtioplal
 
powerpoint feb
powerpoint febpowerpoint feb
powerpoint febimu409
 
Multi graph encoder
Multi graph encoderMulti graph encoder
Multi graph encoder
Yajie Zhou
 
constructor & destructor in cpp
constructor & destructor in cppconstructor & destructor in cpp
constructor & destructor in cpp
gourav kottawar
 
Geek Time Janvier 2017 : Quiz Java
Geek Time Janvier 2017 : Quiz JavaGeek Time Janvier 2017 : Quiz Java
Geek Time Janvier 2017 : Quiz Java
OLBATI
 

What's hot (6)

3.2 stacks and arrays
3.2   stacks and arrays3.2   stacks and arrays
3.2 stacks and arrays
 
Comp 328 final guide
Comp 328 final guideComp 328 final guide
Comp 328 final guide
 
powerpoint feb
powerpoint febpowerpoint feb
powerpoint feb
 
Multi graph encoder
Multi graph encoderMulti graph encoder
Multi graph encoder
 
constructor & destructor in cpp
constructor & destructor in cppconstructor & destructor in cpp
constructor & destructor in cpp
 
Geek Time Janvier 2017 : Quiz Java
Geek Time Janvier 2017 : Quiz JavaGeek Time Janvier 2017 : Quiz Java
Geek Time Janvier 2017 : Quiz Java
 

Similar to Object Oriented Programming Assignment 4

Object Oriented Programming Assignment 2
Object Oriented Programming Assignment 2Object Oriented Programming Assignment 2
Object Oriented Programming Assignment 2
Kasun Ranga Wijeweera
 
Object Oriented Programming Assignment 1
Object Oriented Programming Assignment 1Object Oriented Programming Assignment 1
Object Oriented Programming Assignment 1
Kasun Ranga Wijeweera
 
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
gilbertkpeters11344
 
Cis247 i lab 2 of 7 employee class
Cis247 i lab 2 of 7 employee classCis247 i lab 2 of 7 employee class
Cis247 i lab 2 of 7 employee classsdjdskjd9097
 
Assignment Java Programming 2
Assignment Java Programming 2Assignment Java Programming 2
Assignment Java Programming 2
Kaela Johnson
 
Cis247 i lab 2 of 7 employee class
Cis247 i lab 2 of 7 employee classCis247 i lab 2 of 7 employee class
Cis247 i lab 2 of 7 employee classsdjdskjd9097
 
Cis247 a ilab 2 of 7 employee class
Cis247 a ilab 2 of 7 employee classCis247 a ilab 2 of 7 employee class
Cis247 a ilab 2 of 7 employee classccis224477
 
Cis247 a ilab 2 of 7 employee class
Cis247 a ilab 2 of 7 employee classCis247 a ilab 2 of 7 employee class
Cis247 a ilab 2 of 7 employee classcis247
 
SE-IT JAVA LAB SYLLABUS
SE-IT JAVA LAB SYLLABUSSE-IT JAVA LAB SYLLABUS
SE-IT JAVA LAB SYLLABUS
nikshaikh786
 
C++ Lab Maual.pdf
C++ Lab Maual.pdfC++ Lab Maual.pdf
C++ Lab Maual.pdf
Thejeswara Reddy
 
C++ Lab Maual.pdf
C++ Lab Maual.pdfC++ Lab Maual.pdf
C++ Lab Maual.pdf
ShivamParjapati2
 
Lecture 2 - Classes, Fields, Parameters, Methods and Constructors
Lecture 2 - Classes, Fields, Parameters, Methods and ConstructorsLecture 2 - Classes, Fields, Parameters, Methods and Constructors
Lecture 2 - Classes, Fields, Parameters, Methods and Constructors
Syed Afaq Shah MACS CP
 
Exercise1[5points]Create the following classe
Exercise1[5points]Create the following classeExercise1[5points]Create the following classe
Exercise1[5points]Create the following classe
mecklenburgstrelitzh
 
Assignment Examples Final 07 Oct
Assignment Examples Final 07 OctAssignment Examples Final 07 Oct
Assignment Examples Final 07 OctSriram Raj
 
Assignment Instructions 2_7aExplain the interrelationships bet.docx
Assignment Instructions 2_7aExplain the interrelationships bet.docxAssignment Instructions 2_7aExplain the interrelationships bet.docx
Assignment Instructions 2_7aExplain the interrelationships bet.docx
ssuser562afc1
 
OOP Assignment 03.pdf
OOP Assignment 03.pdfOOP Assignment 03.pdf
OOP Assignment 03.pdf
ARSLANMEHMOOD47
 
Ee java lab assignment 2
Ee java lab assignment 2Ee java lab assignment 2
Ee java lab assignment 2
Kuntal Bhowmick
 
Cis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variablesCis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variablesccis224477
 
Ee java lab assignment 2
Ee java lab assignment 2Ee java lab assignment 2
Ee java lab assignment 2
Kuntal Bhowmick
 

Similar to Object Oriented Programming Assignment 4 (20)

Object Oriented Programming Assignment 2
Object Oriented Programming Assignment 2Object Oriented Programming Assignment 2
Object Oriented Programming Assignment 2
 
Object Oriented Programming Assignment 1
Object Oriented Programming Assignment 1Object Oriented Programming Assignment 1
Object Oriented Programming Assignment 1
 
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
 
Ex
ExEx
Ex
 
Cis247 i lab 2 of 7 employee class
Cis247 i lab 2 of 7 employee classCis247 i lab 2 of 7 employee class
Cis247 i lab 2 of 7 employee class
 
Assignment Java Programming 2
Assignment Java Programming 2Assignment Java Programming 2
Assignment Java Programming 2
 
Cis247 i lab 2 of 7 employee class
Cis247 i lab 2 of 7 employee classCis247 i lab 2 of 7 employee class
Cis247 i lab 2 of 7 employee class
 
Cis247 a ilab 2 of 7 employee class
Cis247 a ilab 2 of 7 employee classCis247 a ilab 2 of 7 employee class
Cis247 a ilab 2 of 7 employee class
 
Cis247 a ilab 2 of 7 employee class
Cis247 a ilab 2 of 7 employee classCis247 a ilab 2 of 7 employee class
Cis247 a ilab 2 of 7 employee class
 
SE-IT JAVA LAB SYLLABUS
SE-IT JAVA LAB SYLLABUSSE-IT JAVA LAB SYLLABUS
SE-IT JAVA LAB SYLLABUS
 
C++ Lab Maual.pdf
C++ Lab Maual.pdfC++ Lab Maual.pdf
C++ Lab Maual.pdf
 
C++ Lab Maual.pdf
C++ Lab Maual.pdfC++ Lab Maual.pdf
C++ Lab Maual.pdf
 
Lecture 2 - Classes, Fields, Parameters, Methods and Constructors
Lecture 2 - Classes, Fields, Parameters, Methods and ConstructorsLecture 2 - Classes, Fields, Parameters, Methods and Constructors
Lecture 2 - Classes, Fields, Parameters, Methods and Constructors
 
Exercise1[5points]Create the following classe
Exercise1[5points]Create the following classeExercise1[5points]Create the following classe
Exercise1[5points]Create the following classe
 
Assignment Examples Final 07 Oct
Assignment Examples Final 07 OctAssignment Examples Final 07 Oct
Assignment Examples Final 07 Oct
 
Assignment Instructions 2_7aExplain the interrelationships bet.docx
Assignment Instructions 2_7aExplain the interrelationships bet.docxAssignment Instructions 2_7aExplain the interrelationships bet.docx
Assignment Instructions 2_7aExplain the interrelationships bet.docx
 
OOP Assignment 03.pdf
OOP Assignment 03.pdfOOP Assignment 03.pdf
OOP Assignment 03.pdf
 
Ee java lab assignment 2
Ee java lab assignment 2Ee java lab assignment 2
Ee java lab assignment 2
 
Cis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variablesCis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variables
 
Ee java lab assignment 2
Ee java lab assignment 2Ee java lab assignment 2
Ee java lab assignment 2
 

More from Kasun Ranga Wijeweera

Decorator Design Pattern in C#
Decorator Design Pattern in C#Decorator Design Pattern in C#
Decorator Design Pattern in C#
Kasun Ranga Wijeweera
 
Singleton Design Pattern in C#
Singleton Design Pattern in C#Singleton Design Pattern in C#
Singleton Design Pattern in C#
Kasun Ranga Wijeweera
 
Introduction to Design Patterns
Introduction to Design PatternsIntroduction to Design Patterns
Introduction to Design Patterns
Kasun Ranga Wijeweera
 
Algorithms for Convex Partitioning of a Polygon
Algorithms for Convex Partitioning of a PolygonAlgorithms for Convex Partitioning of a Polygon
Algorithms for Convex Partitioning of a Polygon
Kasun Ranga Wijeweera
 
Geometric Transformations II
Geometric Transformations IIGeometric Transformations II
Geometric Transformations II
Kasun Ranga Wijeweera
 
Geometric Transformations I
Geometric Transformations IGeometric Transformations I
Geometric Transformations I
Kasun Ranga Wijeweera
 
Introduction to Polygons
Introduction to PolygonsIntroduction to Polygons
Introduction to Polygons
Kasun Ranga Wijeweera
 
Bresenham Line Drawing Algorithm
Bresenham Line Drawing AlgorithmBresenham Line Drawing Algorithm
Bresenham Line Drawing Algorithm
Kasun Ranga Wijeweera
 
Digital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmDigital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing Algorithm
Kasun Ranga Wijeweera
 
Loops in Visual Basic: Exercises
Loops in Visual Basic: ExercisesLoops in Visual Basic: Exercises
Loops in Visual Basic: Exercises
Kasun Ranga Wijeweera
 
Conditional Logic: Exercises
Conditional Logic: ExercisesConditional Logic: Exercises
Conditional Logic: Exercises
Kasun Ranga Wijeweera
 
Getting Started with Visual Basic Programming
Getting Started with Visual Basic ProgrammingGetting Started with Visual Basic Programming
Getting Started with Visual Basic Programming
Kasun Ranga Wijeweera
 
CheckBoxes and RadioButtons
CheckBoxes and RadioButtonsCheckBoxes and RadioButtons
CheckBoxes and RadioButtons
Kasun Ranga Wijeweera
 
Variables in Visual Basic Programming
Variables in Visual Basic ProgrammingVariables in Visual Basic Programming
Variables in Visual Basic Programming
Kasun Ranga Wijeweera
 
Loops in Visual Basic Programming
Loops in Visual Basic ProgrammingLoops in Visual Basic Programming
Loops in Visual Basic Programming
Kasun Ranga Wijeweera
 
Conditional Logic in Visual Basic Programming
Conditional Logic in Visual Basic ProgrammingConditional Logic in Visual Basic Programming
Conditional Logic in Visual Basic Programming
Kasun Ranga Wijeweera
 
Assignment for Variables
Assignment for VariablesAssignment for Variables
Assignment for Variables
Kasun Ranga Wijeweera
 
Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]
Kasun Ranga Wijeweera
 
Assignment for Events
Assignment for EventsAssignment for Events
Assignment for Events
Kasun Ranga Wijeweera
 
Mastering Arrays Assignment
Mastering Arrays AssignmentMastering Arrays Assignment
Mastering Arrays Assignment
Kasun Ranga Wijeweera
 

More from Kasun Ranga Wijeweera (20)

Decorator Design Pattern in C#
Decorator Design Pattern in C#Decorator Design Pattern in C#
Decorator Design Pattern in C#
 
Singleton Design Pattern in C#
Singleton Design Pattern in C#Singleton Design Pattern in C#
Singleton Design Pattern in C#
 
Introduction to Design Patterns
Introduction to Design PatternsIntroduction to Design Patterns
Introduction to Design Patterns
 
Algorithms for Convex Partitioning of a Polygon
Algorithms for Convex Partitioning of a PolygonAlgorithms for Convex Partitioning of a Polygon
Algorithms for Convex Partitioning of a Polygon
 
Geometric Transformations II
Geometric Transformations IIGeometric Transformations II
Geometric Transformations II
 
Geometric Transformations I
Geometric Transformations IGeometric Transformations I
Geometric Transformations I
 
Introduction to Polygons
Introduction to PolygonsIntroduction to Polygons
Introduction to Polygons
 
Bresenham Line Drawing Algorithm
Bresenham Line Drawing AlgorithmBresenham Line Drawing Algorithm
Bresenham Line Drawing Algorithm
 
Digital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmDigital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing Algorithm
 
Loops in Visual Basic: Exercises
Loops in Visual Basic: ExercisesLoops in Visual Basic: Exercises
Loops in Visual Basic: Exercises
 
Conditional Logic: Exercises
Conditional Logic: ExercisesConditional Logic: Exercises
Conditional Logic: Exercises
 
Getting Started with Visual Basic Programming
Getting Started with Visual Basic ProgrammingGetting Started with Visual Basic Programming
Getting Started with Visual Basic Programming
 
CheckBoxes and RadioButtons
CheckBoxes and RadioButtonsCheckBoxes and RadioButtons
CheckBoxes and RadioButtons
 
Variables in Visual Basic Programming
Variables in Visual Basic ProgrammingVariables in Visual Basic Programming
Variables in Visual Basic Programming
 
Loops in Visual Basic Programming
Loops in Visual Basic ProgrammingLoops in Visual Basic Programming
Loops in Visual Basic Programming
 
Conditional Logic in Visual Basic Programming
Conditional Logic in Visual Basic ProgrammingConditional Logic in Visual Basic Programming
Conditional Logic in Visual Basic Programming
 
Assignment for Variables
Assignment for VariablesAssignment for Variables
Assignment for Variables
 
Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]
 
Assignment for Events
Assignment for EventsAssignment for Events
Assignment for Events
 
Mastering Arrays Assignment
Mastering Arrays AssignmentMastering Arrays Assignment
Mastering Arrays Assignment
 

Recently uploaded

Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
Srikant77
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 

Recently uploaded (20)

Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 

Object Oriented Programming Assignment 4

  • 1. Object Oriented Programming in Java [Lesson 1; Lesson 2; Lesson 3; Lesson 4] 1 of 6 Object Oriented Programming Assignment 4 Author: Kasun Ranga Wijeweera Email: krw19870829@gmail.com Date: 2019 October 25 1) Suppose you have to develop an information system for a company. A part of the class diagram is given below. a) Create the class Person that includes attributes: id, name, age, and gender with data types: “int”, “String”, “int”, and “char” respectively. b) Include a constructor to the class Person with parameters: id, name, age, and gender. c) Include getters and setters for each attribute of the class Person. d) Include a method called display to the class Person to display the values of attributes of the class. e) Include a method called getAverageAge to the class Person to get the average age of a person. f) Create the class Customer that includes attributes: level, amount1, amount2, and profit with data types: “int”, “double”, “double”, and “double” respectively. g) Include a constructor to the class Customer with parameters: id, name, age, gender, and level. h) Include getters and setters for each attribute of the class Customer. i) Include a method called display to the class Customer to display the values of attributes of the class. Person Customer Employee FullTimeEmployee PartTimeEmployee
  • 2. Object Oriented Programming in Java [Lesson 1; Lesson 2; Lesson 3; Lesson 4] 2 of 6 j) 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. k) 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. l) Include a method called reduceProfit to the class Customer that computes the value of reduction. The value of reduction is computed by multiplying the value of attribute profit from the value of t. The value of t is based on the value of the attribute level as given in the table below. Furthermore, the value of reduction should be subtracted from the value of attribute profit. level t 1 0.03 2 0.05 3 0.08 4 0.12 m) Create the driver class called Test that includes the “main” method. n) 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. o) Create an array that holds five Customer objects. Assign the objects given in the table below to each array element using the constructor. id name age gender level 3521 Kasun 27 M 3 4863 Nimal 23 M 2 5791 Nayana 28 F 4 2456 Chathura 32 M 1 7593 Waruni 18 F 2 p) Use the method display in the class Test to display the values of attributes of the Customer objects. q) Increment the value of the attribute level of the fourth Customer object by 1.
  • 3. Object Oriented Programming in Java [Lesson 1; Lesson 2; Lesson 3; Lesson 4] 3 of 6 r) Change the value of the attribute gender of the third Customer object to „M‟. s) Use the method display in the class Customer to display the values of attributes of second and third Customer objects. t) Use the method getAverageAge in the class Person to compute the average age of the Customer objects. u) The table given below shows the set of items bought by each of the customer. Use the method 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 v) Use the method calculateProfit in the class Customer to compute the value of the attribute profit of each Customer object. w) Display the value of the attribute profit of each Customer object. x) Compute the new value of the attribute profit of each Customer object using the method reduceProfit in the class Customer. y) Create the class Employee that includes attributes: designation, mobile, salary and tax with data types: “String”, “String”, “double” and “double” respectively. z) Include a constructor to the class Employee with parameters: id, name, age, gender, designation, and mobile. aa) Include getters and setters for each attribute of the class Employee.
  • 4. Object Oriented Programming in Java [Lesson 1; Lesson 2; Lesson 3; Lesson 4] 4 of 6 bb) Include a method called display to the class Employee to display the values of attributes of the class. cc) Include a method called getAverageSalary to the class Employee to get the average salary of an employee. dd) 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. ee) 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. ff) Create the class FullTimeEmployee that includes attributes: fund and fundRate with data types: “double” and “double” respectively. gg) 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. hh) Include getters and setters for each attribute of the class FullTimeEmployee. ii) Include a method called display to the class FullTimeEmployee to display the values of attributes of the class. jj) 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. kk) Create an array that holds seven FullTimeEmployee objects. Assign the objects given in the table below to each array element using the constructor. id name age gender designation mobile fundRate 68494 Nuwan 52 M Manager 0516859465 3% 98451 Charaka 29 M Assistant Manager 0919576348 2% 79563 Wathsala 34 F Clerk 0668567956 1% 36864 Chathurika 35 F Clerk 0219762354 2% 48952 Sandun 27 M Laborer 0319548261 1% 65825 Janith 21 M Laborer 0119652352 0.5% 56286 Chamari 38 F Clerk 0512648927 2%
  • 5. Object Oriented Programming in Java [Lesson 1; Lesson 2; Lesson 3; Lesson 4] 5 of 6 ll) Use the method display in the class Test to display the values of attributes of the FullTimeEmployee objects. mm) Set the value of the attribute salary of each FullTimeEmployee object according to the table given below. id salary 68494 65000 98451 60000 79563 35000 36864 30000 48952 20000 65825 25000 56286 40000 nn) Invoke the method addToFund in the class FullTimeEmployee for each FullTimeEmployee object. The value of the parameter fundRate is computed according to the table given below. id fundRate 68494 4% 98451 3% 79563 2% 36864 1% 48952 2% 65825 2% 56286 1% oo) Create the class PartTimeEmployee that includes attributes: hours and rate with data types: “double” and “double” respectively. pp) Include a constructor to the class PartTimeEmployee with parameters: id, name, age, gender, designation, mobile, and rate. qq) Include getters and setters for each attribute of the class PartTimeEmployee. rr) Include a method called display to the class PartTimeEmployee to display the values of attributes of the class. ss) 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.
  • 6. Object Oriented Programming in Java [Lesson 1; Lesson 2; Lesson 3; Lesson 4] 6 of 6 tt) 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 gender designation mobile rate 68542 Saman 56 M Temporary Clerk 0215698542 300 79546 Nimal 57 M Temporary Laborer 081684952 150 uu) Set the value of the attribute hours of each PartTimeEmployee object according to the table given below. id hours 68542 160 79546 172 vv) Compute the value of the attribute salary of each PartTimeEmployee object by invoking the method computeSalary in the class PartTimeEmployee. ww) Create an array of type Employee that has nine elements. Assign the seven FullTimeEmployee objects and the two PartTimeEmployee objects you have created to each array element. xx) 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. yy) Update the value of the attribute salary of each Employee object using the method getNetSalary of the class Employee. zz) Invoke the method getAverageSalary in the class Employee to compute the average salary of each Employee object.