In: Computer Science
Create an abstract class Employee. Your Employee class should include the following attributes:
First name (string)
Last name (string)
Employee id (string)
Employee home street address (string)
Employee home city (string)
Employee home state (string)
Write a constructor to initialize the above Employee attributes. Create an abstract method called earnings. Create another class HourlyEmployee that inherits from the abstract Employee class. HourEmployee must use the inherited parent class variables and add in attributes HourlyRate and HoursWorked. Your HourEmployee class should contain a constructor that calls the constructor from the Employee class to initialize the common instance variables but also initializes the HourlyRate and HoursWorked. Implement the Employee abstract earnings method in HourlyEmployee to calculate the earnings for a week. Note that earnings is hourly rate * hours worked.
Create a test class that prompts the user for the information for two hourly employees, creates the 2 two hourly employees objects, calls the earnings method then displays the attributes and earnings for each of the two hourly.
SUBMIT YOUR JAVA CODE AND PSUEDOCODE
import java.util.*;
abstract class Employee
{
public String
firstName,lastName,employeeID,address,city,state;
public Employee(String firstName,String lastName,String
employeeID,String address,String city,String state)
{
this.firstName=firstName;
this.lastName=lastName;
this.employeeID=employeeID;
this.address=address;
this.city=city;
this.state=state;
}
abstract double earnings();
}
class HourlyEmployee extends Employee
{
double HourlyRate,HoursWorked;
public HourlyEmployee(String firstName,String lastName,String
employeeID,String address,String city,String state,double
HourlyRate,double HoursWorked)
{
super(firstName,lastName,employeeID,address,city,state);
this.HourlyRate=HourlyRate;
this.HoursWorked=HoursWorked;
}
public double earnings()
{
return HourlyRate*HoursWorked;
}
}
public class Main
{
public static void main(String[] args)
{
Scanner s = new
Scanner(System.in);
String
firstName,lastName,employeeID,address,city,state;
double
HourlyRate,HoursWorked;
System.out.print("Enter the first
name: ");
firstName=s.nextLine();
System.out.print("Enter the last
name: ");
lastName=s.nextLine();
System.out.print("Enter the
employee id: ");
employeeID=s.nextLine();
System.out.print("Enter the
address: ");
address=s.nextLine();
System.out.print("Enter the city:
");
city=s.nextLine();
System.out.print("Enter the state:
");
state=s.nextLine();
System.out.print("Enter the hourly
rate: ");
HourlyRate=s.nextDouble();
System.out.print("Enter the hours
worked: ");
HoursWorked=s.nextDouble();
HourlyEmployee e1 = new
HourlyEmployee(firstName,lastName,employeeID,address,city,state,HourlyRate,HoursWorked);
System.out.println("Earnings :
"+e1.earnings());
System.out.print("Enter the first
name: ");
s.nextLine();
firstName=s.nextLine();
System.out.print("Enter the last
name: ");
lastName=s.nextLine();
System.out.print("Enter the
employee id: ");
employeeID=s.nextLine();
System.out.print("Enter the
address: ");
address=s.nextLine();
System.out.print("Enter the city:
");
city=s.nextLine();
System.out.print("Enter the state:
");
state=s.nextLine();
System.out.print("Enter the hourly
rate: ");
HourlyRate=s.nextDouble();
System.out.print("Enter the hours
worked: ");
HoursWorked=s.nextDouble();
HourlyEmployee e2 = new
HourlyEmployee(firstName,lastName,employeeID,address,city,state,HourlyRate,HoursWorked);
System.out.println("Earnings :
"+e2.earnings());
}
}