?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Moderate

Creating Method in Inherited Class

APCSA-SKE6EO

Consider the following classes.

public abstract class ConstructionWorker 
{
    private String name;
    private double hourlyWage;
    private int numHours;

    public ConstructionWorker(String nam, double wage, int hrs)
    {
        name = nam;
        hourlyWage = wage;
        numHours = hrs;
    }

    public double getHourlyWage()
    {
        return hourlyWage;
    }

    public int getNumHoursOnJob()
    {
        return numHours;
    }

    public String getWorkerName()
    {
        return name;
    }

    public void setHourlyWage(double newWage)
    {
        hourlyWage = newWage;
    }

    public abstract ArrayList<String> determineValidJobs();

    // other data and methods not shown
}
public class Roofer extends ConstructionWorker 
{
    private ArrayList<Tool> tools;

    public Roofer(String nam, double wage, int hrs, ArrayList<Tool> tls)
    {
        super(nam, wage, hrs);
        tools = tls;
    }

    public ArrayList<String> determineValidJobs()
    {
        return new ArrayList<String>();
    }

    // other data and methods not shown
}

A new contract has been signed with the roofer’s union which states that once an hourly wage is established for a roofer, it cannot be reduced.

Which of the following methods could be created in the Roofer class as a way to enforce this restriction?

A
public void setHourlyWage(double wage)
{
    if (wage > getHourlyWage())
        super.setHourlyWage(wage);
}
B
public void setHourlyWage(double wage)
{
    if (wage > Roofer.getHourlyWage())
        Roofer.setHourlyWage(wage);
}
C
public void setHourlyWage(double wage)
{
    if (wage < getHourlyWage())
        super.setHourlyWage(getHourlyWage() + wage);
    else
        super.setHourlyWage(wage);
}
D
public void setHourlyWage(double wage)
{
    if (wage >= this.getHourlyWage())
        setHourlyWage(wage);
}
E
public double getHourlyWage(double wage)
{
    if (wage > super.getHourlyWage())
        super.getHourlyWage(wage);
    return super.getHourlyWage();
}