Assume that the classes listed in the Java Quick Reference have been imported where appropriate.
Unless otherwise noted in the question, assume that parameters in method calls are not null and that methods are called only when their preconditions are satisfied.
In writing solutions for each question, you may use any of the accessible methods that are listed in classes defined in that question. Writing significant amounts of code that can be replaced by a call to one of these methods will not receive full credit.
This question involves the scheduling of car repairs. The classes used in the question are used to record information about car repairs. The methods shown and the methods to be written involve the mechanic performing a repair and the bay in which the repair takes place. A bay is an area of a repair shop in which a car is parked while a mechanic performs a repair. Mechanics and bays are identified by sequential integer identification numbers that start with 0.
An individual car repair is represented by the following CarRepair class.
public class CarRepair
{
private int mechanicNum;
private int bayNum;
public CarRepair(int m, int b)
{
mechanicNum = m;
bayNum = b;
}
public int getMechanicNum()
{ return mechanicNum; }
public int getBayNum()
{ return bayNum; }
// There may be other instance variables, constructors, and methods not shown.
}
The following RepairSchedule class represents the use of bays by mechanics repairing cars. You will write two methods of the RepairSchedule class.
public class RepairSchedule
{
/* Each element represents a repair by an individual mechanic in a bay. /
private ArrayList schedule;
/* Number of mechanics available in this schedule. /
private int numberOfMechanics;
/** Constructs a RepairSchedule object.
* Precondition: n >= 0
*/
public RepairSchedule(int n)
{
schedule = new ArrayList();
numberOfMechanics = n;
}
/** Attempts to schedule a repair by a given mechanic in a given bay as described in part (a).
* Precondition: 0 <= m < numberOfMechanics and b >= 0
*/
public boolean addRepair(int m, int b)
{
/ to be implemented in part (a) /
}
/** Returns an ArrayList containing the mechanic identifiers of all available mechanics,
* as described in part (b).
*/
public ArrayList availableMechanics()
{
/ to be implemented in part (b) /
}
/* Removes an element from schedule when a repair is complete. /
public void carOut(int b)
{
/ implementation not shown /
}
}