Limited access

Upgrade to access all content for this subject

Consider the following class declaration.

/* This class defines an employee  */
public class Employee 
{
    private double baseSalary;        // base salary of employee
    private double potentialBonusAmt; // potential bonus amount

    public Employee(double base, double bonus)
    {
        baseSalary = base;
        potentialBonusAmt = bonus;
    }

    public double calcBaseSalary()
    {
        return baseSalary;
    }

    public double calcBonus()
    {
        return potentialBonusAmt;
    }

    public double calcTotalSalary()
    {
        return calcBaseSalary() + calcBonus();
    }

    public String toString()
    {
        return "The employee has a salary of " + calcTotalSalary();
    }

    // other instance variables and methods not shown
}

A salesman is an employee who has a special bonus incentive program. If the salesman surpasses his/her sales goal, then the salesman will earn the potential bonus on top of his/her base salary. Otherwise, the salesman will not earn his/her bonus and the salesman will only be awarded 90% of his/her normal base salary. When printing the Salesman object, the correct total salary should print as follows:

Employee jeff = new Salesman(60000, 4000, true);
System.out.println(jeff);

would print:
The employee has a salary of 64000.0

Employee joe = new Salesman(60000, 4000, false);
System.out.println(joe);

would print:
The employee has a salary of 54000.0

Which of the following implementations of the Salesman class would satisfy this requirement?

A
public class Salesman extends Employee
{
    boolean surpassGoal;  //has the salesman surpassed their sales goal?

    public Salesman(double salary, double potentialBonusAmt, boolean surpassGoal)
    {
        super(salary, potentialBonusAmt);
        this.surpassGoal = surpassGoal;
    }

    public double calcTotalSalary()
    {
        if (surpassGoal)
            return calcBaseSalary() + calcBonus();
        else
            return calcBaseSalary() * 0.9;
    }
}
B
public class Salesman extends Employee
{
    boolean surpassGoal;  // has the salesman surpassed their sales goal?

    public Salesman2(double salary, double potentialBonusAmt, boolean surpassGoal)
    {
        super(salary, potentialBonusAmt);
        this.surpassGoal = surpassGoal;
    }

    public double calcBonus()
    {
        if (surpassGoal)
            return super.calcBonus();
        return 0;
    }
}
C
public class Salesman extends Employee
{
    boolean surpassGoal;  // has the salesman surpassed their sales goal?

    public Salesman3(double salary, double potentialBonusAmt, boolean surpassGoal)
    {
        super(salary, potentialBonusAmt);
        this.surpassGoal = surpassGoal;
    }

    public double calcBonus()
    {
        if (surpassGoal)
            return calcBonus();
        return 0;
    }

    public double calcTotalSalary()
    {
        if (surpassGoal)
            return calcBaseSalary() + calcBonus();
        else
            return calcBaseSalary() * 0.9;
    }
}
D
public class Salesman extends Employee
{
    boolean surpassGoal;  // has the salesman surpassed their sales goal?

    public Salesman4(double salary, double potentialBonusAmt, boolean surpassGoal)
    {
        super(salary, potentialBonusAmt);
        this.surpassGoal = surpassGoal;
    }

    public double calcBonus()
    {
        if (surpassGoal)
            return calcBonus();
        return 0;
    }

    public String toString()
    {
        return "The employee has a salary of " + calcTotalSalary();
    }
}
E
public class Salesman extends Employee
{
    boolean surpassGoal;  // has the salesman surpassed their sales goal?

    public Salesman5(double salary, double potentialBonusAmt, boolean surpassGoal)
    {
        super(salary, potentialBonusAmt);
        this.surpassGoal = surpassGoal;
    }

    public double calcBonus()
    {
        if (surpassGoal)
            return super.calcBonus();
        return 0;
    }

    public String toString()
    {
        return "The employee has a salary of " + calcTotalSalary();
    }
}
Select an assignment template