Student name: Hatem Saleh Alshamrani
Student number: 445820172.
code
class Main {
public static void main(String[] args) {
SalariedEmployee salariedEmployee = new SalariedEmployee(new Name("John", 'D', "Doe"), new
Date(5, 9, 2020), 50000.0);
HourlyEmployee hourlyEmployee = new HourlyEmployee(new Name("Jane", 'M', "Smith"), new
Date(3, 15, 2019), 20.0, 40.0);
System.out.println("Salaried Employee Gross Pay: $" + salariedEmployee.grossPay());
System.out.println("Hourly Employee Gross Pay: $" + hourlyEmployee.grossPay());
}
}
class Name {
private String first;
private char initial;
private String last;
public Name(String first, char initial, String last) {
this.first = first;
this.initial = initial;
this.last = last;
}
}
class Date {
private int month;
private int day;
private int year;
public Date(int month, int day, int year) {
this.month = month;
this.day = day;
this.year = year;
}
}
class Employee {
protected Name empName;
protected Date hireDate;
public Employee(Name aName, Date aDate) {
empName = aName;
hireDate = aDate;
}
}
class SalariedEmployee extends Employee {
private double annualSalary;
public SalariedEmployee(Name aName, Date aDate, double aSalary) {
super(aName, aDate);
annualSalary = aSalary;
}
public double grossPay() {
return annualSalary;
}
}
class HourlyEmployee extends Employee {
private double hourlyRate;
private double hoursWorked;
public HourlyEmployee(Name aName, Date aDate, double aRate, double aHours) {
super(aName, aDate);
hourlyRate = aRate;
hoursWorked = aHours;
}
public double grossPay() {
return hourlyRate * hoursWorked;
}
}
Output