Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create an abstract Employee business class with these private instance variables

ID: 3750075 • Letter: C

Question

Create an abstract Employee business class with these private instance variables: Employee number: Last name: First name: Email address: 1000-9999 numeric present present present 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 all 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 should

Explanation / Answer

Please do create the appropriate package if required and if you need validation on anoteh field plese do let me know currently added on employee number and social security number.

App.java the class that you need to run

//Employee.java

package business;

public abstract class Employee {

private int emp_no;

private String last_name;

private String first_name;

private String email;

long social_sec_no;

public Employee(){};

public Employee(int emp_no, String last_name, String first_name, String email, long social_sec_no) {

super();

this.emp_no = emp_no;

this.last_name = last_name;

this.first_name = first_name;

this.email = email;

this.social_sec_no = social_sec_no;

}

public abstract double calcpay(double v);

public int getEmp_no() {

return emp_no;

}

public void setEmp_no(int emp_no) {

this.emp_no = emp_no;

}

public String getLast_name() {

return last_name;

}

public void setLast_name(String last_name) {

this.last_name = last_name;

}

public String getFirst_name() {

return first_name;

}

public void setFirst_name(String first_name) {

this.first_name = first_name;

}

public String getEmail() {

return email;

}

public void setEmail(String email) {

this.email = email;

}

public long getSocial_sec_no() {

return social_sec_no;

}

public void setSocial_sec_no(long social_sec_no) {

this.social_sec_no = social_sec_no;

}

@Override

public String toString() {

return " ********************************* "

+ " Employee Info "

+ "********************************* "

+ "Employee Number : "+this.emp_no

+ " Last Name : "+this.last_name

+ " First Name : "+this.first_name

+ " Social Security Number : "+this.social_sec_no

+ " ";

}

}

//HourlyEmployee.java

package business;

public class HourlyEmployee extends Employee{

private int hours_worked;

private final double PER_HOUR_RATE = 15.75;

public HourlyEmployee() {

super();

}

public HourlyEmployee(int emp_no, String last_name, String first_name, String email, long social_sec_no,int hours_worked) {

super(emp_no,last_name,first_name,email,social_sec_no);

this.hours_worked = hours_worked;

}

@Override

public double calcpay(double v) {

return v*PER_HOUR_RATE;

}

public int getHours_worked() {

return hours_worked;

}

public void setHours_worked(int hours_worked) {

this.hours_worked = hours_worked;

}

@Override

public String toString() {

return super.toString()

+ "Hours worked : "+this.hours_worked

+ " Total Pay : "+String.format("%.2f", this.calcpay(hours_worked))+" ";

}

}

//SalaryEmployee.java

package business;

public class SalaryEmployee extends Employee{

private double yearly_sal;

public SalaryEmployee() {

super();

}

public SalaryEmployee(int emp_no, String last_name, String first_name, String email, long social_sec_no,double yearly_sal) {

super(emp_no, last_name, first_name, email, social_sec_no);

this.yearly_sal = yearly_sal;

}

public double getYearly_sal() {

return yearly_sal;

}

public void setYearly_sal(double yearly_sal) {

this.yearly_sal = yearly_sal;

}

@Override

public double calcpay(double v) {

return yearly_sal/12.0;

}

@Override

public String toString() {

return super.toString() + "Month Salary : "+String.format("%.2f", this.calcpay(yearly_sal))+" ";

}

}

//Validation.java

package presentation;

public class Validation {

public static boolean validateEmployeeNumber(String emp_no) {

if(emp_no.isEmpty()||!emp_no.matches("[0-9]+")) {

return false;

}

int temp = Integer.valueOf(emp_no);

if(temp<1000 || temp > 9999)

return false;

return true;

}

public static boolean validateEmployeeSocialSecurityNumber(String val) {

if(val.isEmpty()||!val.matches("[0-9]+")) {

return false;

}

long temp = Long.valueOf(val);

if(temp < 111111111 || temp > 999999999) {

return false;

}

return true;

}

}

//App.java

package presentation;

import java.util.Scanner;

import business.HourlyEmployee;

import business.SalaryEmployee;

public class App {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int emp_n = -1;

long s_s_n = 0l;

while(true) {

while(true) {

System.out.println("Enter the Employee Number [1000 - 9999]: ");

String emp_no =sc.next();

if(Validation.validateEmployeeNumber(emp_no)) {

emp_n = Integer.valueOf(emp_no);

System.out.println();

break;

}

else {

System.out.println("Invalid Employee Number ");

}

}

System.out.println("Enter the Last Name : ");

String l_name = sc.next();

System.out.println();

System.out.println("Enter the first Name : ");

String f_name = sc.next();

System.out.println();

System.out.println("Enter the email : ");

String email = sc.next();

System.out.println();

while(true) {

System.out.println("Enter the social security number [111111111 - 999999999]: ");

String ssn = sc.next();

if(Validation.validateEmployeeSocialSecurityNumber(ssn)) {

s_s_n = Long.valueOf(ssn);

System.out.println();

break;

}

else {

System.out.println("Invaid Social security number ");

}

}

HourlyEmployee hourly = new HourlyEmployee();

hourly.setEmp_no(emp_n);

hourly.setFirst_name(f_name);

hourly.setLast_name(l_name);

hourly.setEmail(email);

hourly.setSocial_sec_no(s_s_n);

SalaryEmployee salary = new SalaryEmployee();

salary.setEmp_no(emp_n);

salary.setFirst_name(f_name);

salary.setLast_name(l_name);

salary.setEmail(email);

salary.setSocial_sec_no(s_s_n);

System.out.println("IS Employee Hourly or Salaried [H/S]");

String is_s_h = sc.next();

int h_w = -1;double y_s;

if(is_s_h.toLowerCase().equals("h")) {

System.out.println("Enter the hours worked : ");

h_w = sc.nextInt();

hourly.setHours_worked(h_w);

System.out.println(hourly);

}

else {

System.out.println("Enter the yearly salary : ");

y_s = sc.nextDouble();

salary.setYearly_sal(y_s);

System.out.println(salary);

}

System.out.println();

System.out.print("Do you like to calculate pay for another : ");

String another = sc.next().toLowerCase();

if(another.equals("y")|| another.equals("yes")) {

continue;

}

else {

System.out.println("Thanks for using application ");

sc.close();

break;

}

}

}

}

//OUTPUT

Enter the Employee Number [1000 - 9999]:
11er
Invalid Employee Number

Enter the Employee Number [1000 - 9999]:
11111
Invalid Employee Number

Enter the Employee Number [1000 - 9999]:
1001

Enter the Last Name :
Roushan

Enter the first Name :
Rakesh

Enter the email :
rake@xyz.eu

Enter the social security number [111111111 - 999999999]:
11er1
Invaid Social security number
Enter the social security number [111111111 - 999999999]:
111111111

IS Employee Hourly or Salaried [H/S]
h
Enter the hours worked :
32

*********************************
Employee Info
*********************************
Employee Number : 1001
Last Name : Roushan
First Name : Rakesh
Social Security Number : 111111111
Hours worked : 32
Total Pay : 504.00


Do you like to calculate pay for another : y
Enter the Employee Number [1000 - 9999]:
1002

Enter the Last Name :
Rahul

Enter the first Name :
kumar

Enter the email :
rah@xyz.eu

Enter the social security number [111111111 - 999999999]:
wer
Invaid Social security number
Enter the social security number [111111111 - 999999999]:
111111112

IS Employee Hourly or Salaried [H/S]
s
Enter the yearly salary :
12456

*********************************
Employee Info
*********************************
Employee Number : 1002
Last Name : Rahul
First Name : kumar
Social Security Number : 111111112
Month Salary : 1038.00


Do you like to calculate pay for another : n
Thanks for using application

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote