The classes Name and Date are separate classes used as properties in the Employee class. Class Employee is the superclass of the classes SalariedEmployee and HourlyEmployee. The superclass has the attributes name and data of hire and methods to set and get these attributes. It also has 2 abstract methods equals() which check if the objects are same and toString() which convert the properties to a printable string. Also the method read() which used as an input method. The SalariedEmployee subclass has in addition to the attributes of the super-class the attribute annualSalary and set and get methods for it. This class also defines the read() method and grossPay() which in this case returns the salary of the employee. The HourlyEmployee subclass has in addition to the attributes of the super-class, the hoursWorked and hourlyRate attributes. It provides ‘get’ and ‘set’ methods for these attributes. Also it provides the methods equals() and toString(). Finally, it provides an implementation of the method grossPay(), which returns the product of the hourly rate with the hours worked for each employee. After creating this class hierarchy create a Main class with a main function. This function will have an array of type Employee and size 2. Place in the position 0 of this array a SalariedEmployee object and in the position 1 an HourlyEmployee object. Then set some appropriate values for the two objects. Finally create a loop that calls the grossPay() method on both objects of the array and display the returned value.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter2: Using Data
Section: Chapter Questions
Problem 14RQ
icon
Related questions
Question
100%
  • The classes Name and Date are separate classes used as properties in the Employee class.
  • Class Employee is the superclass of the classes SalariedEmployee and HourlyEmployee. The superclass has the attributes name and data of hire and methods to set and get these attributes. It also has 2 abstract methods equals() which check if the objects are same and toString() which convert the properties to a printable string. Also the method read() which used as an input method.
  • The SalariedEmployee subclass has in addition to the attributes of the super-class the attribute annualSalary and set and get methods for it. This class also defines the read() method and grossPay() which in this case returns the salary of the employee.
  • The HourlyEmployee subclass has in addition to the attributes of the super-class, the hoursWorked and hourlyRate attributes. It provides ‘get’ and ‘set’ methods for these attributes. Also it provides the methods equals() and toString(). Finally, it provides an implementation of the method grossPay(), which returns the product of the hourly rate with the hours worked for each employee.

After creating this class hierarchy create a Main class with a main function. This function will have an array of type Employee and size 2. Place in the position 0 of this array a SalariedEmployee object and in the position 1 an HourlyEmployee object. Then set some appropriate values for the two objects. Finally create a loop that calls the grossPay() method on both objects of the array and display the returned value.

Employee
# empName : Name
# hireDate : Date
+ Employee (): void
Employee (Name alame, Date aDate) : void
+ read () : void
getEmpNane () : Name
+ getHireDate () : Date
+ setEmpNane (Name newEmpName) : void
+ setHireDate (Date newHireDate) : void
+ tostring() : String
+ equals (Name other) : boolean
HourlyEmployee
SalariedEmployee
- hourlyRate : double
- hoursWorked : double
annualSalary: double
+ SalariedEmployee() : void
+ SalariedEmployee(Name anEmpName,
Date anHireDate, double anSalary) : void
+ read () : void
+ double getAnnualSalary() : double
+ void setAnualSalary(double newRate) : void
+ tostring() : String
+ equals(SalariedEmployee other) : boolean
+ grossPay () : double
+ HourlyEmployee (): void
+ HourlyEmployee (Name anEmpName,
Date alireDate, double anRate,
double anHours) : void
+ read () : void
+ getHourlyRate()
double getHour sWorked () : double
void setHourlyRate(double newRate) : void
setHour sWorked (double newHours) : void
+ tostring 0 : String
+ equals (HourlyEmployee other) : boolean
+ double grossPay ()
double
Transcribed Image Text:Employee # empName : Name # hireDate : Date + Employee (): void Employee (Name alame, Date aDate) : void + read () : void getEmpNane () : Name + getHireDate () : Date + setEmpNane (Name newEmpName) : void + setHireDate (Date newHireDate) : void + tostring() : String + equals (Name other) : boolean HourlyEmployee SalariedEmployee - hourlyRate : double - hoursWorked : double annualSalary: double + SalariedEmployee() : void + SalariedEmployee(Name anEmpName, Date anHireDate, double anSalary) : void + read () : void + double getAnnualSalary() : double + void setAnualSalary(double newRate) : void + tostring() : String + equals(SalariedEmployee other) : boolean + grossPay () : double + HourlyEmployee (): void + HourlyEmployee (Name anEmpName, Date alireDate, double anRate, double anHours) : void + read () : void + getHourlyRate() double getHour sWorked () : double void setHourlyRate(double newRate) : void setHour sWorked (double newHours) : void + tostring 0 : String + equals (HourlyEmployee other) : boolean + double grossPay () double
Write a java program as shown in the following UML class diagram:(read the details below)
Name
- first: String
initial : char
last : String
+ Name (): void
+ Name (String aFirst, char anInitial,
String alast) :void
+ read () : void
+ getFirst () : String
+ getInitial () : char
+ getLast () : String
+ setFirst (String newFirst) : void
+ setInitial (char newInitial) : void
+ void setLast (String newLast) : void
+ tostring () : String
+ equals (Name other) : boolean
Date
int month : int
int day : int
int year : int
+ Date () : void
+ Date (int aMonth, int aDay, int aYear) : void
+ read () : void
+ getMonth ( : int
+ getDay () : int
+ getYear () : int
+ setMonth (int newMonth) : void
+ setDay (int newDay) : void
+ setYear (int newYear) : void
+ tostring () : String
+ equals (Name other) : boolean
Transcribed Image Text:Write a java program as shown in the following UML class diagram:(read the details below) Name - first: String initial : char last : String + Name (): void + Name (String aFirst, char anInitial, String alast) :void + read () : void + getFirst () : String + getInitial () : char + getLast () : String + setFirst (String newFirst) : void + setInitial (char newInitial) : void + void setLast (String newLast) : void + tostring () : String + equals (Name other) : boolean Date int month : int int day : int int year : int + Date () : void + Date (int aMonth, int aDay, int aYear) : void + read () : void + getMonth ( : int + getDay () : int + getYear () : int + setMonth (int newMonth) : void + setDay (int newDay) : void + setYear (int newYear) : void + tostring () : String + equals (Name other) : boolean
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT