Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class Scheduler { private List classes; private List students; public Scheduler() { classes = new ArrayList (); students = new ArrayList (); } public

public class Scheduler { private List classes; private List students; public Scheduler() { classes = new ArrayList(); students = new ArrayList(); } public void addCourse(Course course) { this.classes.add(course); } public List getCourses() { List newCList=new ArrayList<>(); for(int i=0;i

} public List getStudents() { List newSList= new ArrayList<>(); for(int i=0;i

public void assignAll() { int m; int count = 0; int rslt = 0; for(Student student: students){ rslt += student.getPreferences().size(); } while(count<=rslt*rslt){ for(Student student: students){ m = 0; for(Course course: student.getPreferences()){ if(m==0) count++; if(m==0 && this.classes.contains(course) && !course.getRoster().contains(student) && course.getRoster().size()

* Drops a student from a course. public void drop(Student student, Course course) throws IllegalArgumentException { if(!students.contains(student)) throw new IllegalArgumentException("this student is not in the scheduler"); else if(!classes.contains(course)) { throw new IllegalArgumentException("this course is not in the scheduler"); } else //classes.getRoster().remove(course); course.getRoster().remove(student); student.get().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{ if(!students.contains(student)) throw new IllegalArgumentException("this student is not in the scheduler"); else getCourses().removeAll(student.get()); }

}

public class Student { private String name; private int maxCourses; private List preferences; private ArrayList s = new ArrayList(); public Student(String name, int maxCourses, List preferences) throws IllegalArgumentException { this.name = name; this.maxCourses = maxCourses; this.preferences = preferences; if(maxCourses<=0) { throw new IllegalArgumentException("the maxCourses are invalid"); } if(preferences.isEmpty()) { throw new IllegalArgumentException("the preferences are invalid"); } } public String getName() { return name; } public int getMaxCourses() { return maxCourses; } public List getPreferences() { return preferences; } public List getSchedule() { List a = new ArrayList<>(); a.addAll(s);

return new ArrayList<>(a); } public List get(){ return this.s; }

} public class Course { private String courseNumber; private int capacity; private ArrayList r = new ArrayList(); public Course(String courseNumber, int capacity) throws IllegalArgumentException { this.courseNumber = courseNumber; this.capacity = capacity; if(courseNumber.isEmpty()) { throw new IllegalArgumentException("the courseNumber is invalid"); }

if(capacity <=0) { throw new IllegalArgumentException("the capacity is invalid"); } } public int getCapacity() { return capacity; } public String getCourseNumber() { return courseNumber; } public List getRoster() { return this.r; } }

here are the tests that I failed with: How to fix them? @Test public void testThreeThenUnenrollAndReschedule() { Course d = new Course("DUTCH100", 2); Course e = new Course("ECON100", 3); Student s = new Student("s", 3, Arrays.asList(new Course[] {a, b, c, d, e})); Student t = new Student("t", 4, Arrays.asList(new Course[] {c, a, d, e, b})); Student u = new Student("u", 5, Arrays.asList(new Course[] {b, a, d, c, e})); scheduler.addStudent(s); scheduler.addStudent(t); scheduler.addStudent(u); scheduler.addCourse(a); scheduler.addCourse(b); scheduler.addCourse(c); scheduler.addCourse(d); scheduler.addCourse(e); scheduler.assignAll(); scheduler.unenroll(s); scheduler.assignAll(); checkList(Arrays.asList(new Student[] {s, t, u}), scheduler.getStudents()); checkList(Arrays.asList(new Course[] {a, b, c, d, e}), scheduler.getCourses()); checkList(Arrays.asList(new Student[] {t, s}), a.getRoster()); checkList(Arrays.asList(new Student[] {u, s}), b.getRoster()); assertEquals(Arrays.asList(new Student[] {t}), c.getRoster()); checkList(Arrays.asList(new Student[] {u, t}), d.getRoster()); checkList(Arrays.asList(new Student[] {t, u, s}), e.getRoster()); checkList(Arrays.asList(new Course[] {a, b, e}), s.getSchedule()); checkList(Arrays.asList(new Course[] {c, a, e, d}), t.getSchedule()); checkList(Arrays.asList(new Course[] {b, d, e}), u.getSchedule()); } }

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Repairing And Querying Databases Under Aggregate Constraints

Authors: Sergio Flesca ,Filippo Furfaro ,Francesco Parisi

2011th Edition

146141640X, 978-1461416401

More Books

Students also viewed these Databases questions

Question

What is a new-venture team?

Answered: 1 week ago