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

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

ID: 3625122 • Letter: C

Question

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

import java.io.*;

class Employee
{
private String FirstName;
private String LastName;
private long EmpNum;
public Employee(String first,String last,long num)
{
FirstName=first;
LastName=last;
EmpNum=num;
}
public String getFirstName()
{
return FirstName;
}
public String getLastName()
{
return LastName;
}
public long getEmpNum()
{
return EmpNum;
}
}

class HourlyEmployee extends Employee
{
private int shift;
private double HourlyRate;
public HourlyEmployee(String first,String last,long num,int s,double rate)
{
super(first,last,num);
shift=s;
HourlyRate=rate;
}

public void ToString()
{
System.out.println("Employee type: Hourly Employee");
System.out.println("Employee FirstName: "+getFirstName());
System.out.println("Employee LastName: "+getLastName());
System.out.println("Employee Number: "+getEmpNum());
System.out.println("Working Shifts: "+shift);
System.out.println("Hourly Rate: "+HourlyRate);
}
}

class SalaryEmployee extends Employee
{
private double YearlySalary;
public SalaryEmployee(String first,String last,long num,double sal)
{
super(first,last,num);
YearlySalary=sal;
}

public void ToString()
{
System.out.println("Employee type: Salary Employee");
System.out.println("Employee FirstName: "+getFirstName());
System.out.println("Employee LastName: "+getLastName());
System.out.println("Employee Number: "+getEmpNum());
System.out.println("Yearly Salary: "+YearlySalary);
}
}

public class EmployeeDemo
{
public static void main(String args[]) throws Exception
{
Employee e;
SalaryEmployee se;
HourlyEmployee he;

DataInputStream dis =new DataInputStream(System.in);
System.out.println("Enter Hourly Employee Details: ");
System.out.println("Employee First Name: ");
String first=dis.readLine();
System.out.println("Employee Last Name: ");
String last=dis.readLine();
System.out.println("Employee number: ");
long num=Long.parseLong(dis.readLine());
System.out.println("Employee shifts: ");
int shifts=Integer.parseInt(dis.readLine());
System.out.println("Hourly Rate: ");
double rate=Double.parseDouble(dis.readLine());

he=new HourlyEmployee(first,last,num,shifts,rate);

he.ToString();

System.out.println("Enter Salary Employee Details: ");
System.out.println("Employee First Name: ");
first=dis.readLine();
System.out.println("Employee Last Name: ");
last=dis.readLine();
System.out.println("Employee number: ");
num=Long.parseLong(dis.readLine());

System.out.println("Yearly Salary: ");
double sal=Double.parseDouble(dis.readLine());
se=new SalaryEmployee(first,last,num,sal);
se.ToString();
}
}

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