Answer To: Exercise 9.5 JHTP: Draw an inheritance hierarchy for students at a university similar to the...
Aditya answered on May 04 2021
code3/BasePlusCommissionEmployee.java
code3/BasePlusCommissionEmployee.java
public class BasePlusCommissionEmployee extends CommissionEmployee {
private double baseSalary; // base salary per week
// constructor
public BasePlusCommissionEmployee(String firstName, String lastName,String socialSecurityNumber,int month,int day,int year, double grossSales,double commissionRate, double baseSalary)
{
super(firstName, lastName, socialSecurityNumber,month,day,year,grossSales, commissionRate);
if (baseSalary<0.0)
{ // validate baseSalary
throw new IllegalArgumentException("Base salary must be >= 0.0");
}
this.baseSalary = baseSalary;
}
// set base salary
public void setBaseSalary(double baseSalary)
{
if (baseSalary<0.0)
{ // validate baseSalary
throw new IllegalArgumentException("Base salary must be >= 0.0");
}
this.baseSalary = baseSalary;
}
// return base salary
public double getBaseSalary()
{
return baseSalary;
}
// calculate earnings; override method earnings in CommissionEmployee
@Override
public double earnings()
{
return getBaseSalary() + super.earnings();
}
// return String representation of BasePlusCommissionEmployee object
@Override
public String toString()
{
return String.format("%s %s; %s: $%,.2f","base-salaried", super.toString(),"base salary", getBaseSalary());
}
}
code3/CommissionEmployee.java
code3/CommissionEmployee.java
public class CommissionEmployee extends Employee
{
private double grossSales; // gross weekly sales
private double commissionRate; // commission percentage
// constructor
public CommissionEmployee(String firstName, String lastName,String socialSecurityNumber,int month,int day,int year, double grossSales,double commissionRate)
{
super(firstName, lastName, socialSecurityNumber,month,day,year);
if (commissionRate<= 0.0 || commissionRate>= 1.0) // validate
{
throw new IllegalArgumentException("Commission rate must be > 0.0 and < 1.0");
}
if (grossSales<0.0)
{ // validate
throw new IllegalArgumentException("Gross sales must be >= 0.0");
}
this.grossSales = grossSales;
this.commissionRate = commissionRate;
}
// set gross sales amount
public void setGrossSales(double grossSales)
{
if (grossSales<0.0)
{ // validate
throw new IllegalArgumentException("Gross sales must be >= 0.0");
}
this.grossSales = grossSales;
}
// return gross sales amount
public double getGrossSales()
{
return grossSales;
}
// set commission rate
public void setCommissionRate(double commissionRate)
{
if (commissionRate<= 0.0 || commissionRate>= 1.0)
{ // validate
throw new IllegalArgumentException("Commission rate must be > 0.0 and < 1.0");
}
this.commissionRate = commissionRate;
}
// return commission rate
public double getCommissionRate()
{
return commissionRate;
}
// calculate earnings; override abstract method earnings in Employee
@Override
public double earnings()
{
return getCommissionRate() * getGrossSales();
}
// return String representation of CommissionEmployee object
@Override
public String toString() {
return String.format("%s: %s%n%s: $%,.2f; %s: %.2f","commission employee", super.toString(),"gross sales", getGrossSales(),"commission rate", getCommissionRate());
}
}
code3/Date.java
code3/Date.java
public class Date
{
private int month; // 1-12
private int day; // 1-31 b...