Redo the class Employee and the class HourlyEmployee in Displays 7.2 and 7.3 so that the class Date is an inner class of the class Employee and an inherited inner class of the class HourlyEmployee. Also, do a suitable test program.
Program:
NOTE: Please refer the textbook for the classes Employee, Date, and HourlyEmployee
// Employee.java
import java.util.Scanner;
public class Employee
{
// inner class
public class Date
{
// Refer the textbook for the code of this Date class
}
private String name;
private Date hireDate;
// Refer the textbook for the code of this Employee class
}
// HourlyEmployee.java
public class HourlyEmployee extends Employee
{
// Refer the textbook for the code of this HourlyEmployee class
}
// TestHourlyEmployee.java
public class TestHourlyEmployee
{
public static void main(String[] args)
{
Employee employee1 = new Employee();
Employee.Date date1 = employee1.new Date();
HourlyEmployee hourlyEmployee1 = new HourlyEmployee(
"John Smith", date1, 45.45, 172);
HourlyEmployee hourlyEmployee2 = new HourlyEmployee();
hourlyEmployee2.setName("Steven Lee");
hourlyEmployee2.setHireDate(employee1.new Date(4, 28,
2015));
hourlyEmployee2.setRate(50.50);
hourlyEmployee2.setHours(168);
System.out.println("Hourly Employee #1");
System.out.println(hourlyEmployee1);
System.out.printf("Total pay: $%.2f\n", hourlyEmployee1.getPay());
System.out.println("\nHourly Employee #2");
System.out.println(hourlyEmployee2);
System.out.printf("Total pay: $%.2f\n", hourlyEmployee2.getPay());
}
}
Output:
Hourly Employee #1
John Smith January 1, 1000
$45.45 per hour for 172.0 hours
Total pay: $7817.40
Hourly Employee #2
Steven Lee April 28, 2015
$50.5 per hour for 168.0 hours
Total pay: $8484.00