?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Difficult

Carpenter & Construction Worker Classes

APCSA-EFKFEB

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 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;
    }

    public Carpenter(String nam, double wage, int hrs)
    {
        super(nam, wage, hrs);
        //toolboxes = boxes;
    }

    public ArrayList<String> determineValidJobs()
    {
        // Implementation not shown
    }

    public void hammer()
    {
        // Implementation not shown
    }

    // other data and methods not shown
}

Which of the following statements will produce an error (will NOT compile)?

Assume that a valid array list of tool boxes is created as follows:

ArrayList<Toolbox> toolboxes = // list of toolboxes
A
ConstructionWorker mary = new Carpenter("Mary", 12.50, 40, toolboxes);
System.out.println(mary.determineValidJobs());
B
ConstructionWorker bob = new Carpenter("Bob", 12.50, 40, toolboxes);
bob.hammer();
C
Carpenter janice = new Carpenter("Janice", 12.50, 40, toolboxes);
janice.hammer();
D
Carpenter frank = new Carpenter("Frank", 12.50, 40, toolboxes);
frank.setHourlyWage(15.00);
E
Carpenter sam = new Carpenter("Sam", 12.50, 40, toolboxes);
System.out.println(sam.determineValidJobs());