In: Computer Science
**JAVA LANGUAGE**
This assignment will use the Employee class that you developed for assignment 6. Design two sub- classes of Employee...FullTimeEmployee and HourlyEmployee. A full-time employee has an annual salary attribute and may elect to receive life insurance. An hourly employee has an hourly pay rate attribute, an hours worked attribute for the current pay period, a total hours worked attribute for the current year, a current earnings attribute (for current pay period), a cumulative earnings attribute (for the current year), and can work a maximum of 980 hours per year. An hourly employee that works more than 40 hours in a pay period 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. Draw a UML diagram for the classes and show all attributes and methods.
2. Implement the classes and write a test program that creates two full-time employees and two hourly employees. One of the full-time employees should elect the life insurance option. 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.
Here is the answer for your question in Java Programming Language.
Kindly upvote if you find the answer helpful.
NOTE : I could help you with the coding part alone due to time concerns, my sincere apologies for this. Kindly post UML class diagram as a question so that we can help you soon.
######################################################################
CODE :
Employee.java
class Employee { public String getFirstName() { return firstName; } public void setFirstName(String firstName) {
this.firstName = firstName; } @Override |
########################################################################
MyDate.java
@Override |
#####################################################################
FullTimeEmployee.java
public class FullTimeEmployee extends Employee{ public FullTimeEmployee(double annualSalary,boolean
electedLIC,String firstName, String lastName, MyDate hiredDate,
String street, String city, String state, int zip, int employeeNo,
int employeeNumber) { @Override |
#################################################################
HourlyEmployee.java
public class HourlyEmployee
extends Employee{ private double hourlyPayRate = 250.50; private int hoursWorked = 0; private double currentEarnings; private double totalHrsWorked = 0; private double cummulativeEarnings = 0; //Parameterised constructor public HourlyEmployee(int hoursWorked,String fname, String lname, MyDate hireDate, String street, String city, String state, int zip, int employeeNO, int employeeNumber) { super(fname, lname, hireDate, street, city, state, zip, employeeNO, employeeNumber); this.hoursWorked = hoursWorked; this.totalHrsWorked += this.hoursWorked; if(totalHrsWorked > 980){ totalHrsWorked = 980; } } //Getters public double getHourlyPayRate() { return hourlyPayRate; } public int getHoursWorked() { return hoursWorked; } public double getEarnings() { return currentEarnings; } public double getTotalHrsWorked() { return totalHrsWorked; } public double getCummulativeEarnings() { return cummulativeEarnings; } //Setters public void setHoursWorked(int hoursWorked) { this.hoursWorked = hoursWorked; } //Method to calculate earnings public void calculateEarnings(){ if(this.hoursWorked > 40){ this.hourlyPayRate = 1.5 * this.hourlyPayRate; } this.currentEarnings = this.hourlyPayRate * this.hoursWorked; this.cummulativeEarnings += this.currentEarnings; } //toString() method @Override public String toString() { return "Hourly Employee\n=======================\n" + super.toString() + "\nHourly PayRate : $" + hourlyPayRate + "\nHours Worked : " + hoursWorked + "\nCurrent Earnings : $" + currentEarnings + "\nTotal Hours Worked : " + totalHrsWorked + "\nCummulative Earnings : $" + cummulativeEarnings; } } |
##################################################################
EmployeeTest.java
public class EmployeeTest
{ public static void main(String[] args){ FullTimeEmployee obj1 = new FullTimeEmployee(500000,false,"John","Doe",new MyDate("19/09/2005"),"ABC Street","Gorger City","Chicago",123456,9087,8907); FullTimeEmployee obj2 = new FullTimeEmployee(1000000,true,"Luois","Philips",new MyDate("25/09/2006"),"ABC Street","Hulber City","Chicago",34526,1212,3453); HourlyEmployee obj3 = new HourlyEmployee(35,"James","Willis",new MyDate("25/10/2009"),"YHU Street","Milton City","Washington",90983,1235,8938); HourlyEmployee obj4 = new HourlyEmployee(60,"Albert","Thomas",new MyDate("10/10/2007"),"KOL Street","HillBurg City","New York",290398,8733,1092); obj3.calculateEarnings(); obj4.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); System.out.println(); System.out.println(obj4); } } |
###################################################################
SCREENSHOTS :
Please see the screenshots of the code below for the indentations of the code.
Employee.java
#############################################################
MyDate.java
######################################################################
HourlyEmployee.java
#################################################################
FullTimeEmployee.java
####################################################################
EmployeeTest.java
########################################################################
OUTPUT :
Any doubts regarding this can be explained with pleasure :)