Design two sub- classes of Employee...SalariedEmployee and HourlyEmployee. A salaried employee has an annual salary attribute. An hourly employee has an hourly pay rate attribute, an hours worked attribute, and an earnings attribute. An hourly employee that works more than 40 hours gets paid at 1.5 times their hourly pay rate. You will decide how to implement constructors, getters, setters, and any other methods that might be necessary. 1. 2. (20 points) Draw a UML diagram for the classes. (80 points) Implement the classes, and write a test program that creates a salaried employee and two hourly employees. One of the hourly employees should have hours worked set to less than 40 and one should have hours worked set to more than 40. The test program should display all attributes for the three employees. To keep things simple, the employee classes don’t need to do any editing.
Here is my employee class code:
class Employee {
// Declared employee variables
private int employeeNumber;
private int employeeNO;
private MyDate hireDate;
private String street;
private String city;
private String state;
private String fname;
private String lname;
private int zip;
//Parameterized constructor
public Employee(String fname, String lname, MyDate hireDate,
String street, String city, String state, int zip,int employeeNO, int employeeNumber) {
super();
this.employeeNumber = employeeNumber;
this.employeeNO = employeeNO;
this.fname = fname;
this.lname = lname;
this.hireDate = hireDate;
this.street = street;
this.city = city;
this.state = state;
this.zip = zip;
}
Here is the answer for your question in Java Programming Language.
Kindly upvote if you find the answer helpful.
NOTE : Since it is mentioned in the question to display all attributes of each employee, I had to write toString() method in Employee class because all the attributes are private and we cannot access them from other classes.
So to display common attributes of an employee, there should be a toString() in Employee Class. As you haven't provided MyDate class or its description, I have written sample code. Please comment below if you have any doubts.
################################################################################
CODE :
Employee.java
class Employee { // Declared employee variables //Parameterized constructor } @Override |
############################################################
MyDate.java
public class MyDate { @Override |
##########################################################
SalariedEmployee.java
public class SalariedEmployee extends Employee{ @Override |
########################################################
HourlyEmployee.java
public class HourlyEmployee extends Employee{ public int getHoursWorked() { return hoursWorked; } public double getEarnings() { return earnings; } public void setHoursWorked(int hoursWorked) { //Method to calculate earnings @Override |
#################################################################
EmployeeTest.java
public class EmployeeTest
{ public static void main(String[] args){ SalariedEmployee obj1 = new SalariedEmployee(500000,"John","Doe",new MyDate("19/09/2005"),"ABC Street","Gorger City","Chicago",123456,9087,8907); HourlyEmployee obj2 = new HourlyEmployee(35,"James","Willis",new MyDate("25/10/2009"),"YHU Street","Milton City","Washington",90983,1235,8938); HourlyEmployee obj3 = new HourlyEmployee(60,"Albert","Thomas",new MyDate("10/10/2007"),"KOL Street","HillBurg City","New York",290398,8733,1092); obj2.calculateEarnings(); obj3.calculateEarnings(); //Displaying all attributes of the three employees one by one System.out.println(obj1); System.out.println(); System.out.println(obj2); System.out.println(); System.out.println(obj3); } } |
####################################################################
SCREENSHOTS :
Please see the screenshots of the code below for the idnentations of the code.
Employee.java
MyDate.java
#####################################################
SalariedEmployee.java
#######################################################
HourlyEmployee.java
####################################################
EmployeeTest.java
#############################################################
OUTPUT :
Any doubts regarding this can be explained with pleasure :)
Get Answers For Free
Most questions answered within 1 hours.