public class CourseEnrollment
{
/** The number of seats currently available in the course */
private int seatsRemaining;
/** The list of enrolled students, names separated by a single space */
private String roster; // Initialized to "" in the constructor
/**
* Initializes the course with a specified number of seats and an empty roster.
* Precondition: seats > 0
*/
public CourseEnrollment(int seats)
{ /* implementation not shown */ }
/**
* Returns true if the student with the given name meets the
* prerequisites for the course, false otherwise.
* Precondition: name is not null
*/
public boolean checkPrereq(String name)
{ /* implementation not shown */ }
/**
* Enrolls a student if there are seats available and the student
* meets the prerequisites, as described in part (a).
* Precondition: name is not null
*/
public boolean enrollStudent(String name)
{ /* to be implemented in part (a) */ }
/**
* Processes a string of names from a waitlist and attempts to enroll
* each student, as described in part (b).
* Precondition: names ends with a space.
*/
public int processWaitList(String names)
{ /* to be implemented in part (b) */ }
/* There may be instance variables, constructors, and methods
that are not shown. */
}Example 1
| Method Call | checkPrereq(name) | seatsRemaining (before) | Return Value | seatsRemaining (after) |
|---|---|---|---|---|
| enrollStudent("Alex") | true | 2 | true | 1 |
| enrollStudent("Sam") | false | 1 | false | 1 |
| enrollStudent("Jordan") | true | 1 | true | 0 |
| enrollStudent("Casey") | true | 0 | false | 0 |
/** * Enrolls a student if there are seats available and the student * meets the prerequisites, as described in part (a). * Precondition: name is not null */ public boolean enrollStudent(String name)
Example 1
| Method Call | Return Value |
|---|---|
| processWaitList("Alex Sam Jordan ") | 2 |
/** * Processes a string of names from a waitlist and attempts to enroll * each student, as described in part (b). * Precondition: names ends with a space. */ public int processWaitList(String names)