Question

In: Computer Science

**JAVA LANGUAGE** This assignment will use the Employee class that you developed for assignment 6. Design...

**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.

Solutions

Expert Solution

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 {
// Declared employee variables
private String firstName;
private String lastName;
private MyDate hiredDate;
private String street;
private String city;
private String state;
private int zip;
private int employeeNo;
private int employeeNumber;
  
//Parameterized constructor
public Employee(String firstName, String lastName, MyDate hiredDate, String street,
String city, String state, int zip, int employeeNo, int employeeNumber) {
this.firstName = firstName;
this.lastName = lastName;
this.hiredDate = hiredDate;
this.street = street;
this.city = city;
this.state = state;
this.zip = zip;
this.employeeNo = employeeNo;
this.employeeNumber = employeeNumber;
}
//Accessors

public String getFirstName() { return firstName; }
public String getLastName() { return lastName; }
public MyDate getHiredDate() { return hiredDate; }
public String getStreet() { return street; }
public String getCity() { return city; }
public String getState() { return state; }
public int getZip() { return zip; }
public int getEmployeeNo() { return employeeNo; }
public int getEmployeeNumber() { return employeeNumber; }
  
//Mutators

public void setFirstName(String firstName) { this.firstName = firstName; }
public void setLastName(String lastName) { this.lastName = lastName; }
public void setHiredDate(MyDate hiredDate) { this.hiredDate = hiredDate; }
public void setStreet(String street) { this.street = street; }
public void setCity(String city) { this.city = city; }
public void setState(String state) { this.state = state; }
public void setZip(int zip) { this.zip = zip; }
public void setEmployeeNo(int employeeNo) { this.employeeNo = employeeNo; }
public void setEmployeeNumber(int employeeNumber) { this.employeeNumber = employeeNumber; }

@Override
public String toString() {
return "Employee Details : " + "\nName : " + firstName + " " + lastName + "\nEmployeeNo : " + employeeNo
+ "\nEmployee Number : " + employeeNumber + "\nHired Date : " + hiredDate + "\nStreet : " + street
+ "\nCity : " + city + "\nState : " + state + "\nZip : " + zip;
}
}

########################################################################

MyDate.java


public class MyDate {
private String date;
public MyDate(String date){
this.date = date;
}

@Override
public String toString() {
return date ;
}
}

#####################################################################

FullTimeEmployee.java


import java.text.DecimalFormat;

public class FullTimeEmployee extends Employee{
private double annualSalary;
private boolean electedLIC;

public FullTimeEmployee(double annualSalary,boolean electedLIC,String firstName, String lastName, MyDate hiredDate, String street, String city, String state, int zip, int employeeNo, int employeeNumber) {
super(firstName, lastName, hiredDate, street, city, state, zip, employeeNo, employeeNumber);
this.annualSalary = annualSalary;
this.electedLIC = electedLIC;
}
  
//Accessors
public double getAnnualSalary() { return annualSalary; }
public boolean isElectedLIC() { return electedLIC; }
  
//Mutators
public void setAnnualSalary(double annualSalary) { this.annualSalary = annualSalary; }
public void setElectedLIC(boolean electedLIC) { this.electedLIC = electedLIC; }

@Override
public String toString() {
return "Salaried Employee : \n=========================\n"
+ super.toString() + "\nAnnual Salary : " + new DecimalFormat("#.00").format(annualSalary)
+ "\nElected for LIC : " + ((electedLIC)?"YES":"NO");
}
}

#################################################################

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 :)


Related Solutions

This assignment will use the Employee class that you developed for assignment 6. Design two subclasses...
This assignment will use the Employee class that you developed for assignment 6. Design two subclasses 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....
program language: JAVA For this project, you get to design and write a WeightedCourseGrade class to...
program language: JAVA For this project, you get to design and write a WeightedCourseGrade class to keep track of a student's current grade. You also get to design and write WeightedCourseGradeDriver class that requests input from the user and interacts with the WeightedCourseGrade class. Your WeightedCourseGrade class should store the following information: Weighted subtotal (the sum of all of the categories multiplied by the grade category weight) Total category weights (the sum of all the grade category weights) Provide the...
answer in JAVA language please In this assignment you will use: one-dimensional arrays; strings and various...
answer in JAVA language please In this assignment you will use: one-dimensional arrays; strings and various string-handling methods; file input and output; console input and output; loops; and conditional program statements. Instruction You are asked to write a program that translates a Morse code message into English language. The program will ask the user to enter filenames for two input files, one for the code translation table data and the other for the coded message data, as well as an...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class,...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class, you are to have the following data members: name: String (5 pts) id: String   (5 pts) hours: int   (5 pts) rate: double (5 pts) private members (5 pts) You are to create no-arg and parameterized constructors and the appropriate setters(accessors) and getters (mutators). (20 pts) The class definition should also handle the following exceptions: An employee name should not be empty, otherwise an exception...
Java Programming language. Proof of concept class design based on the following ideas Look at your...
Java Programming language. Proof of concept class design based on the following ideas Look at your refrigerator and think about how you would model it as a class. Considerations include: A refrigerator is made by a company on a manufacturing date and has an overall size based on length, width, and height A refrigerator contains a number of shelves and drawers for storing dairy, meats, and vegetables A refrigerator also has storage areas on the door for things like bottled...
PROGRAMMING LANGUAGE : JAVA Problem specification. In this assignment, you will create a simulation for a...
PROGRAMMING LANGUAGE : JAVA Problem specification. In this assignment, you will create a simulation for a CPU scheduler. The number of CPU’s and the list of processes and their info will be read from a text file. The output, of your simulator will display the execution of the processes on the different available CPU’s. The simulator should also display: -   The given info of each process -   CPU utilization - The average wait time - Turnaround time for each process...
Programming Language: JAVA In this assignment you will be sorting an array of numbers using the...
Programming Language: JAVA In this assignment you will be sorting an array of numbers using the bubble sort algorithm. You must be able to sort both integers and doubles, and to do this you must overload a method. Bubble sort work by repeatedly going over the array, and when 2 numbers are found to be out of order, you swap those two numbers. This can be done by looping until there are no more swaps being made, or using a...
Class Employee (All IN JAVA) public class Employee {public String strName, strSalary; public Employee(){strName = "...
Class Employee (All IN JAVA) public class Employee {public String strName, strSalary; public Employee(){strName = " ";strSalary = "$0";} public Employee(String Name, String Salary){strName = Name;strSalary = Salary;} public void setName(String Name){strName = Name;} public void setSalary(String Salary){strSalary = Salary;}public String getName(){return strName;} public String getSalary(){return strSalary;} public String toString(){return(strName + " has a salary of " + strSalary); Create another method to return the name and salary nicely formatted as a string (hint – research the toString method). You...
Design a class named Employee. The class should keep the following information in fields: ·         Employee...
Design a class named Employee. The class should keep the following information in fields: ·         Employee name ·         Employee number in the format XXX–L, where each X is a digit within the range 0–9 and the L is a letter within the range A–M. ·         Hire date Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that inherits from the Employee class. The ProductionWorker class should have fields...
Design a class named Employee. The class should keep the following information in fields: ·         Employee...
Design a class named Employee. The class should keep the following information in fields: ·         Employee name ·         Employee number in the format XXX–L, where each X is a digit within the range 0–9 and the L is a letter within the range A–M. ·         Hire date Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that inherits from the Employee class. The ProductionWorker class should have fields...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT