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.
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
- 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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F30d90cb2-5a82-47cb-ae84-879577ccd5e8%2F8bf2eb53-004d-4313-bd2c-c006c7be4d5d%2Fj0489x8_processed.png&w=3840&q=75)
![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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F30d90cb2-5a82-47cb-ae84-879577ccd5e8%2F8bf2eb53-004d-4313-bd2c-c006c7be4d5d%2Fo3j40nj_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)