Question

Design two sub- classes of Employee...SalariedEmployee and HourlyEmployee. A salaried employee has an annual salary attribute....

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;

}

Homework Answers

Answer #1

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
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;

}

@Override
public String toString() {
return "Employee : " + "\nEmployeeNumber : " + employeeNumber + "\nEmployee NO" + employeeNO + "\nName : " + fname + " " + lname + "\nHireDate : " + hireDate.toString()
+ "\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 ;
}
}

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

SalariedEmployee.java

public class SalariedEmployee extends Employee{
  
private double annualSalary;
  
public SalariedEmployee(double annualSalary,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.annualSalary = annualSalary;
}
  
//Getter
public double getAnnualSalary() {
return annualSalary;
}
  
//Setter
public void setAnnualSalary(double annualSalary) {
this.annualSalary = annualSalary;
}
  
//toString() method

@Override
public String toString() {
return "Salaried " + super.toString() + "\nAnnual Salary : $" + annualSalary;
}
  
  
}

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

HourlyEmployee.java

public class HourlyEmployee extends Employee{
private double hourlyPayRate = 250.50;
private int hoursWorked = 0;
private double earnings;
//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;
}
  
//Getters
public double getHourlyPayRate() { return hourlyPayRate; }

public int getHoursWorked() { return hoursWorked; }

public double getEarnings() { return earnings; }
  
//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.earnings = this.hourlyPayRate * this.hoursWorked;
}
  
//toString() method

@Override
public String toString() {
return "Hourly " + super.toString() + "\nHourly PayRate : $" + hourlyPayRate + "\nHours Worked : " + hoursWorked + "\nEarnings : $" + earnings ;
}
  
}

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

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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
**JAVA LANGUAGE** Write a program that models an employee. An employee has an employee number, a...
**JAVA LANGUAGE** Write a program that models an employee. An employee has an employee number, a name, an address, and a hire date. A name consists of a first name and a last name. An address consists of a street, a city, a state (2 characters), and a 5-digit zip code. A date consists of an integer month, day and year. All fields are required to be non-blank. The Date fields should be reasonably valid values (ex. month 1-12, day...
Java Programming COMP-228 LAB ASSIGNMENT #1 >> Apply the naming conventions for variables, methods, classes, and...
Java Programming COMP-228 LAB ASSIGNMENT #1 >> Apply the naming conventions for variables, methods, classes, and packages: - variable names start with a lowercase character for the first word and uppercase for every other word - classes start with an uppercase character of every word - packages use only lowercase characters - methods start with a lowercase character for the first word and uppercase for every other word Java Programming COMP-228 Exercise #1: [5 marks] Write a Java application using...
Objectives:The focus of this assignment is to create and use a recursive method given a moderately...
Objectives:The focus of this assignment is to create and use a recursive method given a moderately difficult problem. Program Description: This project will alter the EmployeeManager to add a search feature, allowing the user to find an Employee by a substring of their name. This will be done by implementing the Rabin-Karp algorithm. A total of seven classes are required. Employee (From previous assignment) HourlyEmployee (From previous assignment) SalaryEmployee (From previous assignment) CommissionEmployee (From previous assignment) EmployeeManager (Altered from previous...
Prevosti Farms and Sugarhouse pays its employees according to their job classification. The following employees make...
Prevosti Farms and Sugarhouse pays its employees according to their job classification. The following employees make up Sugarhouse's staff: Employee Number Name and Address Payroll information A-Mille Thomas Millen Hire Date: 2-1-2019 1022 Forest School Rd DOB: 12-16-1982 Woodstock, VT 05001 Position: Production Manager 802-478-5055 PT/FT: FT, exempt SSN: 031-11-3456 No. of Exemptions: 4 401(k) deduction: 3% M/S: M Pay Rate: $35,000/year A-Towle Avery Towle Hire Date: 2-1-2019 4011 Route 100 DOB: 7-14-1991 Plymouth, VT 05102 Position: Production Worker 802-967-5873...
Team 5 answer the questions What are 4 key things you learned about the topic from...
Team 5 answer the questions What are 4 key things you learned about the topic from reading their paper? How does the topic relate to you and your current or past job? Critique the paper in terms of the organization and quality. Incentive Systems             In this paper, we will focus primarily on financial rewards that companies use to attract, retain and motivate the brightest and most talented candidates in the labor market. By providing a reward system that...
Please answer the following Case analysis questions 1-How is New Balance performing compared to its primary...
Please answer the following Case analysis questions 1-How is New Balance performing compared to its primary rivals? How will the acquisition of Reebok by Adidas impact the structure of the athletic shoe industry? Is this likely to be favorable or unfavorable for New Balance? 2- What issues does New Balance management need to address? 3-What recommendations would you make to New Balance Management? What does New Balance need to do to continue to be successful? Should management continue to invest...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how the firms resources incompetencies support the given pressures regarding costs and local responsiveness. Describe entry modes have they usually used, and whether they are appropriate for the given strategy. Any key issues in their global strategy? casestudy: Atlanta, June 17, 2014. Sea of Delta employees and their families swarmed between food trucks, amusement park booths, and entertainment venues that were scattered throughout what would...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT