Question: How do I fix them I have three classes public class Scheduler { private List courseList; private List studentList; /** * Instantiates a new, empty

How do I fix them I have three classes

public class Scheduler {

private List courseList;

private List studentList;

/** * Instantiates a new, empty scheduler. */

public Scheduler() { courseList=new ArrayList<>();

studentList=new ArrayList<>(); }

/** * Adds a course to the scheduler. * * @param course * the course to be added */ public void addCourse(Course course) { courseList.add(course); }

/** * Returns the list of courses that this scheduler knows about. * * This returned object does not share state with the internal state of the * Scheduler. * * @return the list of courses */ public List getCourses() { List newCourses=new ArrayList<>();

for(int i=0;i

{

newCourses.add(courseList.get(i));

}

return newCourses; }

/** * Adds a student to the scheduler. * @param student * the student to add */ public void addStudent(Student student) { studentList.add(student); }

/** * Returns a list of the students this scheduler knows about. * * This returned object does not share state with the internal state of the * Scheduler. * * @return */ public List getStudents() { List newRoster= new ArrayList<>();

for(int i=0;i

{

newRoster.add(studentList.get(i));

}

return newRoster;

}

/** * Assigns all students to courses in the following manner: * * For a given student, check their list of preferred courses. Add them to the * course that: - exists in the scheduler's list of courses - the student most * prefers (that is, comes first in their preference list) - the student is not * not already enrolled in - and is not full (in other words, at capacity) Adds * courses to the *end* of the student's current list of classes. Adds students * to the *end* of the course's roster. * Repeat this process for each student, one-by-one; each student will now have * one course, usually (but not always) their most preferred course. * Then repeat this whole process (adding one course per student, when possible, * proceeding round-robin among students), until there is nothing left to do: * Students might all be at their maximum number of courses, or there may be no * available seats in courses that students want. */ public void assignAll() { for (Student s : studentList) { for (Course c : s.getPreferences()) { if (courseList.contains(c)) { if (c.getCapacity() > 0 && !c.getRoster().contains(s)) { c.getRoster().add(s); break; } } } }

}

/** * Drops a student from a course. * * @param student * @param course * @throws IllegalArgumentException * if either the student or the course are not known to this * scheduler */ public void drop(Student student, Course course) throws IllegalArgumentException {

studentList.remove(student); course.getRoster().remove(student); courseList.remove(course); }

/** * Drops a student from all of their courses. * * @param student * @throws IllegalArgumentException * if the student is not known to this scheduler */ public void unenroll(Student student) throws IllegalArgumentException { for (Course c : courseList) { c.getRoster().remove(student); } }

package scheduler; public class Student { private String name; private int maxCourses; private List preferences; private List Schedule; public Student(String name, int maxCourses, List preferences) throws IllegalArgumentException { this.name= name; this.maxCourses= maxCourses; this.preferences= preferences; Schedule = new ArrayList<>(); if(maxCourses<=0) throw new IllegalArgumentException("the student's maximum course load must"+" be greater than zero");

else if(preferences.isEmpty()) throw new IllegalArgumentException("the preferences list must contain at "+"least one course"); } public String getName() { return name; } public int getMaxCourses() { return maxCourses; } public List getPreferences() { return preferences; } public List getSchedule() { return Schedule; } }

import java.util.List; import java.util.ArrayList; public class Course { private String courseNumber; private int capacity; private List Roster; public Course(String courseNumber, int capacity) throws IllegalArgumentException {

this.courseNumber=courseNumber;

this.capacity=capacity;

Roster=new ArrayList<>();

if(courseNumber.isEmpty())

throw new IllegalArgumentException

("the course number must be nonempty");

else if(capacity<=0)

throw new IllegalArgumentException

("the course number must be nonempty"); } public int getCapacity() { return capacity; } public String getCourseNumber() { return courseNumber; } public List getRoster() { return Roster; } }

Here are the tests that I failed:

@Test public void testOtherFull() { Student s = new Student("s", 2, listAC); Student t = new Student("t", 2, listCA); List listT = Arrays.asList(new Student[] {t}); List listST = Arrays.asList(new Student[] {s, t}); List listTS = Arrays.asList(new Student[] {t, s}); scheduler.addStudent(t); scheduler.addStudent(s); scheduler.addCourse(a); scheduler.addCourse(c); scheduler.assignAll(); checkList(listTS, scheduler.getStudents()); checkList(listAC, scheduler.getCourses()); checkList(listST, a.getRoster()); assertEquals(listT, c.getRoster()); assertEquals(listA, s.getSchedule()); checkList(listCA, t.getSchedule()); }

@Test public void testSingleCourse() { Student s = new Student("s", 1, listA); List listS = Arrays.asList(new Student[] {s}); scheduler.addStudent(s); scheduler.addCourse(a); scheduler.assignAll(); assertEquals(listS, scheduler.getStudents()); assertEquals(listA, scheduler.getCourses()); assertEquals(listS, a.getRoster()); assertEquals(listA, s.getSchedule()); }

@Test public void testTwoInTwo() { Student s = new Student("s", 2, listAB); Student t = new Student("t", 2, listBA); List listST = Arrays.asList(new Student[] {s, t}); List listTS = Arrays.asList(new Student[] {t, s}); scheduler.addStudent(s); scheduler.addStudent(t); scheduler.addCourse(a); scheduler.addCourse(b); scheduler.assignAll(); checkList(listST, scheduler.getStudents()); checkList(listAB, scheduler.getCourses()); checkList(listST, a.getRoster()); checkList(listTS, b.getRoster()); checkList(listAB, s.getSchedule()); checkList(listBA, t.getSchedule()); }

@Test public void testGetScheduleEmptyNotShared() { List schedule = joe.getSchedule(); schedule.add(new Course("COMPSCI190D", 120)); assertTrue(joe.getSchedule().isEmpty()); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!