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

Make sure when your program begins you display a description of what the program

ID: 3625485 • Letter: M

Question

Make sure when your program begins you display a description of what the program does for the user and what inputs they will be required to enter.



Create a class named Employee. The class should store the following information.

first name
last name
employee number


Create a class named HourlyEmployee that inherits from the Employee class. This class should store the following additional pieces of information:

shift ( "days" OR "swings" OR "mids" )
hourly rate



Create a class named SalaryEmployee that inherits from the Employee class. This class should store the following additional information:

Yearly salary



For all three of the classes:

all fields should be declared to have private access
all fields should have accessor ( get ) and mutator ( set ) methods
there should be a single constructor that requires values for ALL of the fields in the class ( and for its superclass )
there should be a toString method that displays a formatted mini report including ALL of the fields of the class ( including any in the superclass )



Create a test class called TestEmployeeClasses

Create 1 object of each class: Employee, HourlyEmployee, and SalaryEmployee
Prompt the user of your program ( AFTER displaying a description of your program first… ) to enter in the information required to create the 3 objects.
Test all of the get/set methods for all of the objects.
For each of the objects display a report ( using the toString method for the object )

Explanation / Answer

// The complete program has 4 classes ... look at the classes carefully and the package positioning...... // You could omit the package statement and place all the files in a single package.... /******Important comments*******/ /****You could also execute everything in a single file by removing the public for Employee, SalaryEmployee and HourlyEmployee classes ..... and then place them all in single java file EmployeeMain.java***************/ EmployeeMain.java --------------------------- package employeemain; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class EmployeeMain { public static void main(String[] args) { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); try{ System.out.println(" Employee Information system"); System.out.println("Consists of three classes Employee,HourlyEmployee and SalaryEmployee"); System.out.println("Testing all the method of the classes -*********"); //Employee Class System.out.println(" Testing Employee class with firstname,lastname and employee number"); System.out.println("Enter firstName(String):"); String firstName=br.readLine(); System.out.println("Enter LastName(String):"); String lastName=br.readLine(); System.out.println("Enter employeeNumber(String):"); String employeeNumber=br.readLine(); Employee e=new Employee(firstName,lastName,employeeNumber); System.out.println(" Employee object created with constructor"); System.out.println(" Employee details with getter methods firstName"+e.getFirstName()+" lastName:"+e.getLastName()+" employeeNumber:"+e.getEmployeeNumber()); System.out.println(" Editting the employee details with setter method"); System.out.println(" Enter first name to edit:"); firstName=br.readLine(); e.setFirstName(firstName); System.out.println(" Enter last name to edit:"); lastName=br.readLine(); e.setLastName(lastName); System.out.println(" Enter employee number to edit:"); employeeNumber=br.readLine(); e.setEmployeeNumber(employeeNumber); System.out.println(" Details of the employee after editing using toString():"+e.toString()); //Hourly Employee class System.out.println(" Testing HourlyEmployee class inheriting Employee and extra fields shift and Hourly rate"); System.out.println("Enter firstName(String):"); firstName=br.readLine(); System.out.println("Enter LastName(String):"); lastName=br.readLine(); System.out.println("Enter employeeNumber(String):"); employeeNumber=br.readLine(); System.out.println("Enter shift(String- days OR swings OR mids):"); String shift=br.readLine(); System.out.println("Enter Hourly Rate(double):"); Double hourlyRate=Double.parseDouble(br.readLine()); HourlyEmployee he=new HourlyEmployee(firstName,lastName,employeeNumber,shift,hourlyRate); System.out.println(" HourlyEmployee object created with constructor"); System.out.println(" HourlyEmployee details with getter methods firstName"+he.getFirstName()+" lastName:"+he.getLastName()+" employeeNumber:"+he.getEmployeeNumber()+" Shift:"+he.getShift()+" Hourly Rate:"+he.getHourlyRate()); System.out.println(" Editting the HourlyEmployee details with setter method"); System.out.println(" Enter first name to edit:"); firstName=br.readLine(); he.setFirstName(firstName); System.out.println(" Enter last name to edit:"); lastName=br.readLine(); he.setLastName(lastName); System.out.println(" Enter employee number to edit:"); employeeNumber=br.readLine(); he.setEmployeeNumber(employeeNumber); System.out.println(" Enter shift(String- days OR swings OR mids) to edit:"); shift=br.readLine(); he.setShift(shift); System.out.println(" Enter Hourly Rate(double) to edit:"); hourlyRate=Double.parseDouble(br.readLine()); he.setHourlyRate(hourlyRate); System.out.println(" Details of the Hourly Employee after editing using toString():"+he.toString()); //SalaryEmployee System.out.println(" Testing SalaryEmployee class inheriting Employee and extra fields yearlySalary"); System.out.println("Enter firstName(String):"); firstName=br.readLine(); System.out.println("Enter LastName(String):"); lastName=br.readLine(); System.out.println("Enter employeeNumber(String):"); employeeNumber=br.readLine(); System.out.println("Enter Yearly Salary(double):"); Double yearlySalary=Double.parseDouble(br.readLine()); SalaryEmployee se=new SalaryEmployee(firstName,lastName,employeeNumber,yearlySalary); System.out.println(" SalaryEmployee object created with constructor"); System.out.println(" SalaryEmployee details with getter methods firstName"+se.getFirstName()+" lastName:"+se.getLastName()+" employeeNumber:"+se.getEmployeeNumber()+" yearly salary:"+se.getYearlySalary()); System.out.println(" Editting the SalaryEmployee details with setter method"); System.out.println(" Enter first name to edit:"); firstName=br.readLine(); se.setFirstName(firstName); System.out.println(" Enter last name to edit:"); lastName=br.readLine(); se.setLastName(lastName); System.out.println(" Enter employee number to edit:"); employeeNumber=br.readLine(); se.setEmployeeNumber(employeeNumber); System.out.println(" Enter Yearly Salary(double) to edit:"); yearlySalary=Double.parseDouble(br.readLine()); se.setYearlySalary(yearlySalary); System.out.println(" Details of the Hourly Employee after editing using toString():"+se.toString()); } catch(NumberFormatException e){ //e.printStackTrace(); System.out.println("*********Invalid input********"); } catch(IOException e){ //e.printStackTrace(); System.out.println("*********Error Reading from keyboard//Enter valid input********"); } } } Employee.java ------------------- package employeemain; public class Employee { private String firstName; private String lastName; private String employeeNumber; public Employee(){ } public Employee(String firstName,String lastName,String employeeNumber){ this.firstName=firstName; this.lastName=lastName; this.employeeNumber=employeeNumber; } 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 getEmployeeNumber() { return employeeNumber; } public void setEmployeeNumber(String employeeNumber) { this.employeeNumber = employeeNumber; } public String toString(){ return " First Name:"+firstName+" Last Name:"+lastName+" Employee Number:"+employeeNumber; } } HourlyEmployee.java ------------------------------- package employeemain; public class HourlyEmployee extends Employee{ private String shift; private double hourlyRate; public HourlyEmployee(){ } public HourlyEmployee(String firstName,String lastName,String employeeNumber, String shift,double hourlyRate){ super(firstName,lastName,employeeNumber); this.shift=shift; this.hourlyRate=hourlyRate; } public String getShift() { return shift; } public void setShift(String shift) { this.shift = shift; } public double getHourlyRate() { return hourlyRate; } public void setHourlyRate(double hourlyRate) { this.hourlyRate = hourlyRate; } public String toString(){ return super.toString()+", shift"+shift+", hourlyRate"+hourlyRate; } } SalaryEmployee.java --------------------------- package employeemain; public class SalaryEmployee extends Employee{ private double yearlySalary; public SalaryEmployee(){ } public SalaryEmployee(String firstName,String lastName,String employeeNumber,double yearlySalary){ super(firstName,lastName,employeeNumber); this.yearlySalary=yearlySalary; } public double getYearlySalary() { return yearlySalary; } public void setYearlySalary(double yearlySalary) { this.yearlySalary = yearlySalary; } public String toString(){ return super.toString()+", Yearly Salary"+yearlySalary; } }

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