Can I get some help creating a java method? These are the requirements for the dropStudent() method I need to make:
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
Main method:
public class interactiveCourseDriver { public static void main(String[] args) { Student[] studentsInSchool = new Student[15]; studentsInSchool[0] = new Student("Adam", "Ant", "S925", true); studentsInSchool[1] = new Student("Bob", "Barker", "S713", false); studentsInSchool[2] = new Student("Chevy", "Chase", "S512", true); studentsInSchool[3] = new Student("Doris", "Day", "S513", true); studentsInSchool[4] = new Student("Emilio", "Estevez", "S516", true); studentsInSchool[5] = new Student("Farrah", "Fawcet", "S956", true); studentsInSchool[6] = new Student("Greta", "Garbo", "S419", true); studentsInSchool[7] = new Student("Helen", "Hunt", "S281", true); studentsInSchool[8] = new Student("Jack", "Johnson", "S790", true); studentsInSchool[9] = new Student("Kim", "Kardashian", "S336", true); studentsInSchool[10] = new Student("Martina", "McBride", "S156", true); studentsInSchool[11] = new Student("Renne", "Russo", "S219", true); studentsInSchool[12] = new Student("Susan", "Serandon", "S472", true); studentsInSchool[13] = new Student("Vince", "Vaughn", "S892", true); studentsInSchool[14] = new Student("Walt", "Whitman", "S901", true); Course course = new Course("Media Studies", 5, 5); System.out.println(course + "\n"); System.out.println("*****TESTING DROPS"); Student studentToDrop = studentsInSchool[2]; boolean dropped = course.dropStudent(studentToDrop); System.out.println(studentToDrop + (dropped ? " dropped successfully" : " not dropped")); System.out.println("\n" + course + "\n"); studentToDrop = studentsInSchool[14]; dropped = course.dropStudent(studentToDrop); System.out.println(studentToDrop + (dropped ? " dropped successfully" : " not dropped")); System.out.println("\n" + course + "\n"); studentToDrop = studentsInSchool[8]; dropped = course.dropStudent(studentToDrop); System.out.println(studentToDrop + (dropped ? " dropped successfully" : " not dropped")); System.out.println("\n" + course + "\n"); studentToDrop = studentsInSchool[0]; dropped = course.dropStudent(studentToDrop); System.out.println(studentToDrop + (dropped ? " dropped successfully" : " not dropped")); System.out.println("\n" + course + "\n"); } }
public class Course { private String courseName; private int maxRoster = 5; private int maxWaitlist = 5; private Student[] roster = new Student[maxRoster]; private Student[] waitlist = new Student[maxWaitlist]; public Course.
Can I get some help creating a java method- These are the requirements.docx
1. Can I get some help creating a java method? These are the requirements for the dropStudent()
method I need to make:
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
Main method:
public class interactiveCourseDriver { public static void main(String[] args) { Student[]
studentsInSchool = new Student[15]; studentsInSchool[0] = new Student("Adam", "Ant",
"S925", true); studentsInSchool[1] = new Student("Bob", "Barker", "S713", false);
studentsInSchool[2] = new Student("Chevy", "Chase", "S512", true); studentsInSchool[3] = new
Student("Doris", "Day", "S513", true); studentsInSchool[4] = new Student("Emilio", "Estevez",
"S516", true); studentsInSchool[5] = new Student("Farrah", "Fawcet", "S956", true);
studentsInSchool[6] = new Student("Greta", "Garbo", "S419", true); studentsInSchool[7] = new
Student("Helen", "Hunt", "S281", true); studentsInSchool[8] = new Student("Jack", "Johnson",
"S790", true); studentsInSchool[9] = new Student("Kim", "Kardashian", "S336", true);
studentsInSchool[10] = new Student("Martina", "McBride", "S156", true); studentsInSchool[11]
= new Student("Renne", "Russo", "S219", true); studentsInSchool[12] = new Student("Susan",
"Serandon", "S472", true); studentsInSchool[13] = new Student("Vince", "Vaughn", "S892",
true); studentsInSchool[14] = new Student("Walt", "Whitman", "S901", true); Course course =
new Course("Media Studies", 5, 5); System.out.println(course + "n");
System.out.println("*****TESTING DROPS"); Student studentToDrop = studentsInSchool[2];
boolean dropped = course.dropStudent(studentToDrop); System.out.println(studentToDrop +
(dropped ? " dropped successfully" : " not dropped")); System.out.println("n" + course + "n");
studentToDrop = studentsInSchool[14]; dropped = course.dropStudent(studentToDrop);
System.out.println(studentToDrop + (dropped ? " dropped successfully" : " not dropped"));
System.out.println("n" + course + "n"); studentToDrop = studentsInSchool[8]; dropped =
course.dropStudent(studentToDrop); System.out.println(studentToDrop + (dropped ? " dropped
successfully" : " not dropped")); System.out.println("n" + course + "n"); studentToDrop =
studentsInSchool[0]; dropped = course.dropStudent(studentToDrop);
System.out.println(studentToDrop + (dropped ? " dropped successfully" : " not dropped"));
System.out.println("n" + course + "n"); } }
public class Course { private String courseName; private int maxRoster = 5; private int
maxWaitlist = 5; private Student[] roster = new Student[maxRoster]; private Student[] waitlist =
2. new Student[maxWaitlist]; public Course(String courseName, int maxRoster, int maxWaitlist) {
this.courseName = courseName; this.maxRoster = maxRoster; this.maxWaitlist = maxWaitlist; }
public int getMaxRoster() { return maxRoster; } public int getMaxWaitlist() { return
maxWaitlist; } public void setRoster(Student[] roster, Student student, int i) { roster[i] = student;
} public void setWaitlist(Student[] waitlist, Student student, int l) { waitlist[l] = student;; } public
Student[] getRoster() { return roster; } public Student[] getWaitlist() { return waitlist; }
@Override public String toString() { // TODO Add in max waitlist length return courseName +
"n" + roster.length + " enrolled (maximum allowed " + maxRoster + ")n" + waitlist.length + "
enrolled (maximum allowed " + maxWaitlist + ")"; } public void printMenu() {
System.out.println("Please select an option."); System.out.println("1) Add a student");
System.out.println("2) Drop a student"); System.out.println("3) Print the course");
System.out.println("4) Exitn"); } public boolean addStudent(Student student) { boolean
studentAdded = false; int i = 0; int l = 0; if (student.isTuitionPaid()) { if (roster.length <
maxRoster) { studentAdded = true; setRoster(roster, student, i); Array.set(roster, i, student); i++;
} else { studentAdded = false; } if (waitlist.length < maxWaitlist && maxRoster ==
roster.length) { studentAdded = true; setWaitlist(waitlist, student, l); l++; } else { } } return
studentAdded; } } package Project2;
public class Student { private String firstName, lastName, id; private boolean tuitionPaid; public
Student(String firstName, String lastName, String id, boolean tuitionPaid) { this.firstName =
firstName; this.lastName = lastName; this.id = id; this.tuitionPaid = tuitionPaid; } public
Student(Student student) { } public String getFirstName() { return firstName; } public String
getLastName() { return lastName; } public void setFirstName(String firstName) { this.firstName
= firstName; } public void setLastName(String lastName) { this.lastName = lastName; } public
String getID() { return id; } public void setID(String id) { this.id = id; } public boolean
isTuitionPaid() { return tuitionPaid; } public void setTuitionPaid(boolean tuitionPaid) {
this.tuitionPaid = tuitionPaid; } @Override public boolean equals(Object obj) { if(obj != null) {
Student student = (Student)obj; return id.equals(student.id) &&
firstName.equalsIgnoreCase(student.firstName) && lastName.equalsIgnoreCase(lastName) &&
tuitionPaid == student.tuitionPaid; } return false; // obj is null or not an object of Student class }
@Override public String toString() { return firstName + " " + lastName + " (" + id + ")"; } }
Below is the needed output for the test:
Media Studies
0 enrolled (maximum allowed 5)
0 on waitlist (maximum allowed 5)
*****TESTING ADDS
Adam Ant (S925) added successfully
Bob Barker (S713) not added
Chevy Chase (S512) added successfully
Doris Day (S513) added successfully
Emilio Estevez (S516) added successfully
Farrah Fawcet (S956) added successfully
Greta Garbo (S419) added successfully
3. Helen Hunt (S281) added successfully
Jack Johnson (S790) added successfully
Kim Kardashian (S336) added successfully
Martina McBride (S156) added successfully
Renne Russo (S219) not added
Susan Serandon (S472) not added
Vince Vaughn (S892) not added
Walt Whitman (S901) not added
Media Studies
5 enrolled (maximum allowed 5)
Adam Ant (S925)
Chevy Chase (S512)
Doris Day (S513)
Emilio Estevez (S516)
Farrah Fawcet (S956)
5 on waitlist (maximum allowed 5)
Greta Garbo (S419)
Helen Hunt (S281)
Jack Johnson (S790)
Kim Kardashian (S336)
Martina McBride (S156)
Chevy Chase (S512) not added
Media Studies
5 enrolled (maximum allowed 5)
Adam Ant (S925)
Chevy Chase (S512)
Doris Day (S513)
Emilio Estevez (S516)
Farrah Fawcet (S956)
5 on waitlist (maximum allowed 5)
Greta Garbo (S419)
Helen Hunt (S281)
Jack Johnson (S790)
Kim Kardashian (S336)
Martina McBride (S156)
Helen Hunt (S281) not added
Media Studies
5 enrolled (maximum allowed 5)
Adam Ant (S925)
Chevy Chase (S512)
Doris Day (S513)
4. Emilio Estevez (S516)
Farrah Fawcet (S956)
5 on waitlist (maximum allowed 5)
Greta Garbo (S419)
Helen Hunt (S281)
Jack Johnson (S790)
Kim Kardashian (S336)
Martina McBride (S156)
*****TESTING DROPS
Chevy Chase (S512) dropped successfully
Media Studies
5 enrolled (maximum allowed 5)
Adam Ant (S925)
Doris Day (S513)
Emilio Estevez (S516)
Farrah Fawcet (S956)
Greta Garbo (S419)
4 on waitlist (maximum allowed 5)
Helen Hunt (S281)
Jack Johnson (S790)
Kim Kardashian (S336)
Martina McBride (S156)
Walt Whitman (S901) not dropped
Media Studies
5 enrolled (maximum allowed 5)
Adam Ant (S925)
Doris Day (S513)
Emilio Estevez (S516)
Farrah Fawcet (S956)
Greta Garbo (S419)
4 on waitlist (maximum allowed 5)
Helen Hunt (S281)
Jack Johnson (S790)
Kim Kardashian (S336)
Martina McBride (S156)
Jack Johnson (S790) dropped successfully
Media Studies
5 enrolled (maximum allowed 5)
Adam Ant (S925)
Doris Day (S513)
5. Emilio Estevez (S516)
Farrah Fawcet (S956)
Greta Garbo (S419)
3 on waitlist (maximum allowed 5)
Helen Hunt (S281)
Kim Kardashian (S336)
Martina McBride (S156)
Adam Ant (S925) dropped successfully
Media Studies
5 enrolled (maximum allowed 5)
Doris Day (S513)
Emilio Estevez (S516)
Farrah Fawcet (S956)
Greta Garbo (S419)
Helen Hunt (S281)
2 on waitlist (maximum allowed 5)
Kim Kardashian (S336)
Martina McBride (S156)