?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Difficult

Carpenter Class Design

APCSA-XETYNW

A housing contractor uses various construction workers to build a house. One type of construction worker is a carpenter. A carpenter uses various tools which are stored in his toolbox. A carpenter can have multiple toolboxes. Tools are constantly being added and removed from the carpenter’s tool boxes.

Consider the following two classes which define a construction worker and his/her tools.

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 String getWorkerName()
    {
        return name;
    }

    public abstract ArrayList< String > determineValidJobs();

    // other data and methods not shown
}

public class Tool 
{
    private String name;
    private String type;
    private int quantity;
    private String instructions;

    public Tool(String nam, String typ, int qty, String instruct)
    {
        name = nam;
        type = typ;
        quantity = qty;
        instructions = instruct;
    }
    // other data and methods not shown
}

Which of the following would BEST define the relationships between the carpenter and his tools?

A
public class Toolbox 
{
    private String description;
    private ArrayList< Tool > tools;

    public Toolbox(String desc, ArrayList< Tool > tools)
    {
        this.description = desc;
        this.tools = tools;
    }
    // other data and methods not shown
}

public class Carpenter extends ConstructionWorker 
{
    private Toolbox toolbox;

    public Carpenter(String nam, double wage, int hrs, 
                         Toolbox box)
    {
        super(nam, wage, hrs);
        toolbox = box;
    }    

    public ArrayList< String > determineValidJobs()
    {
        // implementation not shown
    }
    // other data and methods not shown
}
B
public class Carpenter extends ConstructionWorker 
{
    private String toolboxDescription;
    private ArrayList< Tool > tools;

    public Carpenter(String nam, double wage, int hrs, 
                         String desc, ArrayList< Toolbox > boxes)
    {
        super(nam, wage, hrs);
        toolboxDescription = desc;
        this.tools = tools;
    }    

    public ArrayList< String > determineValidJobs()
    {
        // implementation not shown
    }
    // other data and methods not shown
}
C
public class Toolbox 
{
    private String description;
    private Tool tools;

    public Toolbox(String desc, Tool tools)
    {
        this.description = desc;
        this.tools = tools;
    }
    // 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 ArrayList< String > determineValidJobs()
    {
        // implementation not shown
    }
    // other data and methods not shown
}
D
public class Toolbox 
{
    private String description;
    private Tool[] tools;

    public Toolbox(String desc, Tool[] tools)
    {
        this.description = desc;
        this.tools = tools;
    }
    // other data and methods not shown
}

public class Carpenter extends ConstructionWorker 
{
    private Toolbox toolbox;

    public Carpenter(String nam, double wage, int hrs, 
                         Toolbox box)
    {
        super(nam, wage, hrs);
        toolbox = box;
    }

    public ArrayList< String > determineValidJobs()
    {
        // implementation not shown
    }
    // other data and methods not shown
}
E
public class Toolbox 
{
    private String description;
    private ArrayList
 tools;

    public Toolbox(String desc, ArrayList< Tool > tools)
    {
        this.description = desc;
        this.tools = tools;
    }
    // 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 ArrayList< String > determineValidJobs()
    {
        // implementation not shown
    }
    // other data and methods not shown
}