A technical workshop offers several sessions throughout the day. The workshop stores information about each session in three parallel arrays.
capacity[i] is the maximum number of students allowed in session i.
enrolled[i] is the number of students currently enrolled in session i.
canceled[i] is true if session i has been canceled and false otherwise.
You will write two methods of the WorkshopSchedule class. A partial class declaration is shown below.
public class WorkshopSchedule
{
private int[] capacity;
private int[] enrolled;
private boolean[] canceled;
// constructor not shown
public int openSeats(int session)
{ /* to be written in part (a) */ }
public int firstAvailableSession(int needed)
{ /* to be written in part (b) */ }
}
Part (a). Write the method openSeats, which returns the number of open seats in session session. If the session is canceled, the method returns 0.
For example, if capacity[2] = 24, enrolled[2] = 19, and canceled[2] = false, then openSeats(2) returns 5. If canceled[2] = true, then openSeats(2) returns 0.
Part (b). Write the method firstAvailableSession, which returns the index of the first session that has at least needed open seats. The method must ignore canceled sessions. If no session has at least needed open seats, the method returns -1.
Assume part (a) works as intended. Your solution to part (b) must call openSeats.