Create an abstract Employee business class with these private instance variables
ID: 3748621 • Letter: C
Question
Create an abstract Employee business class with these private instance variables Employee number: Last name: First name: Email address: Social security number 1000-9999 numeric present present present 111111111-999999999 numeric Include two constructors, an empty constructor, and one that accepts all parameters, and a get and a set method for each of the instance variables. Include in this abstract class an abstract method called calcPay. The abstract method should accept a double parameter and return a double. You will also need to override the toString() method that will displays all the above fields in a formatted version (make it look nice). Create two subclasses that extend Employee, one for hourly employee, and one for salary employee. Both subclasses should override the abstract method in Employee. Hourly subclass: The hourly subclass should contain an instance variable for number of hours worked, two constructors that call the super class, and a get and set method for the instance variable. Hourly rate should be a constant that cannot be changed and set at 15.75. The calcPay method should accept the number of hours worked as the parameter, and calculate an hourly employee's pay by multiplying the number of hours worked by the hourly rate. Salary subclass: The salary subclass should contain an instance variable for yearly salary, two constructors that call the super class, and a get and set method for that instance variable. The calcPay method should accept a yearly salary as the parameter, and calculate a monthly salary by dividing the yearly salary by twelve months. The presentation class should ask for the employee number, last name, first name, email address and social security number. The presentation class's main method should consist almost entirely of method calls. Error checking should be done on user-entered fields using a Validation class. Once the fields have been validated, those values should be passed to business class using the set methods. The application class should also ask if the employee is hourly or salary. Based on that answer; determine which calcPay method to call in order to calculate pay. If the employee is hourly, the application should prompt the user for the number of hours worked. That value shouldExplanation / Answer
Note: I have to provide the Test class.I will update it.Thank You
______________
Employee.java
public abstract class Employee {
//Declaring instance variables
private int empNo;
private String firstname;
private String lastname;
private String email;
private String socialSecurityNumber;
public Employee() {
}
//Parameterised constructor
public Employee(int empNo,String firstname, String lastname,String email,String socialSecurityNumber) {
this.empNo=empNo;
this.firstname = firstname;
this.lastname = lastname;
this.email=email;
this.socialSecurityNumber = socialSecurityNumber;
}
//Setters and Getters.
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getSocialSecurityNumber() {
return socialSecurityNumber;
}
public void setSocialSecurityNumber(String socialSecurityNumber) {
this.socialSecurityNumber = socialSecurityNumber;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public abstract double calcPay(double n);
@Override
public String toString() {
System.out.println("Firstname :"+getFirstname());
System.out.println("Lastname :"+getLastname());
System.out.println("Email :"+email);
System.out.println("Social Security No :"+getSocialSecurityNumber());
return " ";
}
}
___________________
HourlyEmployee.java
public class HourlyEmployee extends Employee {
//Declaring instance variables
private final double HOURLYWAGE=15.75;
private int hoursworked;
//Parameterised constructor
public HourlyEmployee(int empNo,String firstname, String lastname,String email, String ssn,
double hourlyWage, int hoursworked) {
super(empNo,firstname,lastname,email,ssn);
this.hoursworked=hoursworked;
}
//Setters and Getters.
public int getHoursworked() {
return hoursworked;
}
public void setHoursworked(int hoursworked) {
if(hoursworked>0 && hoursworked<=168)
{
this.hoursworked = hoursworked;
}
}
//toString() method will display the contents of the Object.
@Override
public String toString() {
System.out.print("Hourly Employee:");
super.toString();
System.out.println("Hours Worked :"+getHoursworked());
System.out.println("Earnings :"+calcPay(hoursworked));
return " ";
}
@Override
public double calcPay(double n) {
return n*HOURLYWAGE;
}
}
__________________
SalariedEmployee.java
public class SalariedEmployee extends Employee {
// Declaring instance variables
private double ysalary;
// Parameterised constructor
public SalariedEmployee(int empNo,String firstname, String lastname, String email,
String ssn, double ysalary) {
super(empNo,firstname, lastname, email, ssn);
this.ysalary = ysalary;
}
// Setters and Getters.
public double getSalary() {
return ysalary;
}
public void setSalary(double salary) {
if (salary > 0) {
this.ysalary = salary;
}
}
// toString() method will display the contents of the Object.
@Override
public String toString() {
System.out.print("Salaried Employee:");
super.toString();
System.out.println("Salary: : " + getSalary());
System.out.println("Earnings: " + calcPay(ysalary));
return " ";
}
@Override
public double calcPay(double n) {
return n / 12;
}
}
__________________
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.