Exercise 9.5 JHTP: Draw an inheritance hierarchy for students at a university similar to the hierarchy shown in Fig 9.2. Use Student as the superclass of the hierarchy, then, extend Student with...

1 answer below »


Exercise 9.5 JHTP:
Draw an inheritance hierarchy for students at a university similar to the hierarchy shown in Fig 9.2. Use Student as the superclass of the hierarchy, then, extend Student with classes Undergraduate Student and Graduate Student. Continue to extend the hierarchy as deep (i.e., as many levels as possible). For example, Freshmen, Sophomore, Junior, and the Senior might extend Undergraduate Student and Doctoral Student and Masters Student might be subclasses of Graduate Students. After drawing the hierarchy, discuss the relationships that exist between the classes. [Note: You do not need to write any code for this exercise].




Exercise 10.6:
How does polymorphism promote extensibility?




Exercise 10.12:
Payroll Modification Modify the payroll system of Figs 10.4 –10.9 to include private instance variable birthdate in class Employee. Use class Date of Fig 8.7 to represent an employee’s birthday. Add get methods to class Date. Assume that payroll is processed once per month. Create an array of Employee variables to store references to the various employee objects. In a loop, calculate the payroll for each Employee (polymorphic ally), and add a $100.00 bonus to the persons payroll amount if the current month is the one in which the Employee’s birthdate occurs.

Answered Same DayMay 02, 2021

Answer To: Exercise 9.5 JHTP: Draw an inheritance hierarchy for students at a university similar to the...

Aditya answered on May 04 2021
150 Votes
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, d
ouble 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...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here