Limited access

Upgrade to access all content for this subject

Consider the following class declarations.

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 Carpenter extends ConstructionWorker 
{
    private ArrayList< Toolbox > toolboxes;

    public Carpenter(String nam, double wage, int hrs,
                         ArrayList< Toolbox > boxes)
    {
        super(nam, wage, hrs);
        toolboxes = boxes;
    }

    // other data and methods not shown
}

A carpenter intern is like a carpenter in most respects, except that an intern is paid differently. Interns receive their normal hourly rate unless they are scheduled for more than 40 hours on the job. If that is the case, then they must receive a temporary 20% increase in the hourly rate for all hours worked.

Management does not want to modify the intern’s hourly rate in this case; they just want to return the modified rate if the job hours are greater than 40. This is the rate that should be used in calculations.

Of the following, which is the BEST definition of the CarpenterIntern class?

A
public class CarpenterIntern
{
    private String name;
    private double hourlyWage;
    private int numHours;

    public CarpenterIntern(String nam, double wage, 
                           int hrs, ArrayList< Toolbox > boxes)
    {
        name = nam;
        hourlyWage = wage;
        numHours = hrs;
    }

    public double getHourlyWage()
    {
        if (numHours>40)
            return hourlyWage*1.2;
        else
            return hourlyWage;
    }
}
B
public class CarpenterIntern extends Carpenter
{
    public CarpenterIntern(String nam, double wage, 
                           int hrs, ArrayList< Toolbox > boxes)
    {
        super(nam, wage, hrs, boxes);
    }

    public double getHourlyWage()
    {
        if (getNumHoursOnJob()>40)
            return super.getHourlyWage()*1.2;
        else
            return super.getHourlyWage();
    }
}
C
public class CarpenterIntern extends ConstructionWorker
{
    private ArrayList< Toolbox > toolboxes;

    public CarpenterIntern(String nam, double wage, 
                           int hrs, ArrayList< Toolbox > boxes)
    {
        super(nam, wage, hrs);
        toolboxes = boxes;
    }

    public double getHourlyWage()
    {
        if (this.getNumHoursOnJob()>40)
            return super.getHourlyWage()*1.2;
        else
            return super.getHourlyWage();
    }
}
D
public class CarpenterIntern extends Carpenter
{
    public CarpenterIntern(String nam, double wage, 
                           int hrs, ArrayList< Toolbox > boxes)
    {
        super(nam, wage, hrs, boxes);
    }

    public double getHourlyWage()
    {
        if (getNumHoursOnJob()>40)
            return getHourlyWage()*1.2;
        else
            return getHourlyWage();
    }
}
E
public class CarpenterIntern extends Carpenter
{
    public CarpenterIntern(String nam, double wage, 
                           int hrs, ArrayList< Toolbox > boxes)
    {
        super(nam, wage, hrs, boxes);
    }

    public void setHourlyWage()
    {
        if (getNumHoursOnJob()>40)
            setHourlyWage(getHourlyWage()*1.2);
    }
}
Select an assignment template