Part A: The Student Class

Review the provided Student.java class.

Complete the class by writing an equals method to override the equals method inherited from Object. Two students should be considered logically equivalent if they have the same id, first name (ignoring capitalization), last name (ignoring capitalization), and tuition paid status.

Student.java

public class Student {

private String firstName;
private String lastName;
private String id;
private boolean tuitionPaid;

public Student(final String firstName, final String lastName, final String id, final boolean tuitionPaid) {
this.firstName = firstName;
this.lastName = lastName;
this.id = id;
this.tuitionPaid = tuitionPaid;
}

public String getFirstName() {
return this.firstName;
}

public String getLastName() {
return this.lastName;
}

public void setFirstName(final String firstName) {
this.firstName = firstName;
}

public void setLastName(final String lastName) {
this.lastName = lastName;
}

public String getID() {
return this.id;
}

public void setID(final String id) {
this.id = id;
}

public boolean isTuitionPaid() {
return this.tuitionPaid;
}

public void setTuitionPaid(final boolean tuitionPaid) {
this.tuitionPaid = tuitionPaid;
}

@Override
public String toString() {
return firstName + " " + lastName + " (" + id + ")";
}
}

Part B: The Course Class

You will write a Course class. A Course keeps track of Students enrolled in the Course (on the roster) and on the waitlist for the Course. Include:

1. Instance data variables

  • a course name
  • two Student[] objects- one for roster, one for waitlist
  • the maximum number of students allowed on the waitlist and roster
  • any other variables you think are helpful

2. A constructor

  • A Course object is initially created by specifying the maximum number of students allowed on the roster and on the waitlist
  • The roster and waitlist are initially empty

3. Getters and setters

  • Carefully consider which variables should have setters.
  • Include validity checks in setters when appropriate.

4. A toString method whose text representation includes

  • the name of the course
  • the number of students enrolled in the course and the maximum number that can be enrolled
  • the roster of enrolled students (all student data for all enrolled students should be included)
  • the number of students on the waitlist and the maximum number that can be on the waitlist
  • the students on the waitlist (all student data for all waitlisted students should be included)
  • make sure that there are no "nulls" printed with the arrays

5. An addStudent method

  • method header: public boolean addStudent(Student student)
  • if the student has paid their tuition and are not already enrolled on the roster or waitlist, the student is eligible to be added to the class
    • if there is room on the roster, add the student to the roster
    • if the roster is full but there is room on the waitlist, add the student to the waitlist
    • if there is no room on the roster or waitlist, do not add the student
  • if the student has not paid their tuition or is already on the roster or waitlist, do not add the student
  • return true or false based on whether the student is added or not

6. A dropStudent method

  • method header: public boolean dropStudent(Student student)
  • if the student is not on the roster or waitlist, the student cannot be removed
  • if the student is on the roster, remove the student from the roster
    • since there is now one more space in the class, if the waitlist is not empty, take the first person off the waitlist and add them to the roster
  • if the student is on the waitlist, remove the student from the waitlist
  • return true or false based on whether the student is removed or not

Part C: Interactive Driver Program

Write an interactive driver program that creates a Course object (you can decide the name and roster/waitlist sizes). Then, use a loop to interactively allow the user to add students, drop students, or view the course. Display the result (success/failure) of each add/drop.

Extra Credit

Write a class called CourseAL. This class has the same methods as Course (listed above). Instead of using a Student[] to store the roster and waitlist, use an ArrayList< Student >. For full credit, take advantage of the methods in the ArrayList class to implement the methods. Do not just swap out the array for an ArrayList- use the methods from the ArrayList class! You might be able to significantly streamline your code!

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.