Question

I need some help fixing this error. I completed the code, just modify it so the...

I need some help fixing this error. I completed the code, just modify it so the error is gone. I had to remove the imports and parts of the test to fit everything

public class Scheduler {

   private List listOfCourses;

   private List listOfStudents;

   public Scheduler() {

   listOfCourses = new ArrayList();

   listOfStudents = new ArrayList();

   }

   public void addCourse(Course course) {

   listOfCourses.add(course);

   }

   public List getCourses() {

   List courseList = new ArrayList(listOfCourses);

   return courseList;

   }

  

   public void addStudent(Student student) {

   listOfStudents.add(student);

   }

   public List getStudents() {

   List studentList = new ArrayList(listOfStudents);

   return studentList;

   }

  

   /**

   * 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 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() {

   Student johnOrJaneDoe;

   Course desiredCourse;

   Course backUpChoice;

   int times = 0;

   for(int i = 0; i < listOfStudents.size(); i++) {

   if(listOfStudents.get(i).getPreferences().size() > times) {

   times = listOfStudents.get(i).getPreferences().size();

   }

   }

   while(true) {

   for(int i = 0; i < times; i++) {

   for(int st = 0; st < listOfStudents.size(); st++) {

   johnOrJaneDoe = listOfStudents.get(st);

   desiredCourse = johnOrJaneDoe.getPreferences().get(i);

   if(johnOrJaneDoe.getMaxCourses() > johnOrJaneDoe.getSchedule().size()) {

   if(listOfCourses.contains(desiredCourse)) {

   if(desiredCourse.getRoster().contains(johnOrJaneDoe) == false) {

   if(desiredCourse.getRoster().size() < desiredCourse.getCapacity()) {

   johnOrJaneDoe.addClass(desiredCourse);

   desiredCourse.enroll(johnOrJaneDoe);

   }

   else {

   for(int rip = i; rip < johnOrJaneDoe.getPreferences().size(); rip++) {

   backUpChoice = johnOrJaneDoe.getPreferences().get(rip);

   if(backUpChoice.getRoster().size() < backUpChoice.getCapacity()) {

   johnOrJaneDoe.addClass(backUpChoice);

   backUpChoice.enroll(johnOrJaneDoe);

   break;

   }

   }

   }

   }

   }

   }

   }

   }

   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 {

   if(listOfStudents.contains(student) == false || listOfCourses.contains(course) == false) {

   throw new IllegalArgumentException();

   }

   student.dropClass(course);

   course.kickStudent(student);

}

   public void unenroll(Student student) throws IllegalArgumentException{

   if(listOfStudents.contains(student) == false) {

   throw new IllegalArgumentException();

   }

   student.useless();

   for(int i = 0; i < listOfCourses.size(); i++) {

   if(listOfCourses.get(i).getRoster().contains(student)) {

   listOfCourses.get(i).kickStudent(student);

   }

   }

   }

}

SchedulerTest.java

public class SchedulerTest {

   private Scheduler scheduler;
  
   private Scheduler singleScheduler;
   private Course courseOne;
   private Student studentOne;

   private Course a;
   private Course b;
   private Course c;
   private List listA;
   private List listB;
   private List listAB;
   private List listBA;  
   private List listAC;
   private List listCA;  


   @Before
   public void setup() {
       scheduler = new Scheduler();
       courseOne = new Course("ONE1", 1);
       List l = new ArrayList<>();
       l.add(courseOne);
       studentOne = new Student("one", 1, l);
       singleScheduler = new Scheduler();
       singleScheduler.addStudent(studentOne);
       singleScheduler.addCourse(courseOne);

       a = new Course("ANTHRO100", 2);
       b = new Course("BIO100", 2);
       c = new Course("COMM100", 1);
      
       listA = Arrays.asList(new Course[] {a});
       listB = Arrays.asList(new Course[] {b});
       listAB = Arrays.asList(new Course[] {a, b});
       listBA = Arrays.asList(new Course[] {b, a});
       listAC = Arrays.asList(new Course[] {a, c});
       listCA = Arrays.asList(new Course[] {c, a});
   }

   private static void checkList(List expected, List actual) {
       assertEquals(expected.size(), actual.size());
       for (E e: expected) {
           assertTrue(actual.contains(e));
       }
   }

@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()); THIS IS THE ERROR

       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());

   }

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

SchedulerTest.java

import org.junit.Test;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;


public class SchedulerTest {
   // public Timeout globalTimeout = Timeout.seconds(10); // 10 seconds

   private Scheduler scheduler;
  
   private Scheduler singleScheduler;
   private Course courseOne;
   private Student studentOne;

   private Course a;
   private Course b;
   private Course c;
   private List<Course> listA;
   private List<Course> listB;
   private List<Course> listAB;
   private List<Course> listBA;  
   private List<Course> listAC;
   private List<Course> listCA;  

   // This method is run before each test, performing initialization
   // on objects for the test.
   @Before
   public void setup() {
       scheduler = new Scheduler();
       courseOne = new Course("ONE1", 1);
       List<Course> l = new ArrayList<>();
       l.add(courseOne);
       studentOne = new Student("one", 1, l);
       singleScheduler = new Scheduler();
       singleScheduler.addStudent(studentOne);
       singleScheduler.addCourse(courseOne);

       a = new Course("ANTHRO100", 2);
       b = new Course("BIO100", 2);
       c = new Course("COMM100", 1);
      
       listA = Arrays.asList(new Course[] {a});
       listB = Arrays.asList(new Course[] {b});
       listAB = Arrays.asList(new Course[] {a, b});
       listBA = Arrays.asList(new Course[] {b, a});
       listAC = Arrays.asList(new Course[] {a, c});
       listCA = Arrays.asList(new Course[] {c, a});
   }

   private static <E> void checkList(List<E> expected, List<E> actual) {
       assertEquals(expected.size(), actual.size());
       for (E e: expected) {
           assertTrue(actual.contains(e));
       }
   }
  
   @Test
   public void testGetCoursesEmpty() {
       assertTrue(scheduler.getCourses().isEmpty());
   }

   @Test
   public void testGetStudentsEmpty() {
       assertTrue(scheduler.getStudents().isEmpty());
   }

   @Test
   public void testAddOneCourse() {
       assertEquals(1, singleScheduler.getCourses().size());
       assertTrue(singleScheduler.getCourses().contains(courseOne));
   }

   @Test
   public void testAddOneStudent() {
       assertEquals(1, singleScheduler.getStudents().size());
       assertTrue(singleScheduler.getStudents().contains(studentOne));
   }

   @Test
   public void testGetCoursesNotShared() {
       List<Course> l = singleScheduler.getCourses();
       l.clear();
       assertTrue(singleScheduler.getCourses().contains(courseOne));
   }

   @Test
   public void testGetStudentsNotShared() {
       List<Student> l = singleScheduler.getStudents();
       l.clear();
       assertTrue(singleScheduler.getStudents().contains(studentOne));
   }
  
   @Test
   public void testSingleCourse() {      
       Student s = new Student("s", 1, listA);
       List<Student> 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 testDropSimple() {      
       Student s = new Student("s", 1, listA);
       List<Student> listS = Arrays.asList(new Student[] {s});
      
       scheduler.addStudent(s);
       scheduler.addCourse(a);
       scheduler.assignAll();
       scheduler.drop(s, a);
      
       assertEquals(listS, scheduler.getStudents());
       assertEquals(listA, scheduler.getCourses());
       assertTrue(s.getSchedule().isEmpty());
       assertTrue(a.getRoster().isEmpty());
   }

   @Test
   public void testSingleUnavailableCourse() {      
       Student s = new Student("s", 1, listA);
       List<Student> listS = Arrays.asList(new Student[] {s});
      
       scheduler.addStudent(s);
       scheduler.addCourse(b);
       scheduler.assignAll();
      
       assertEquals(listS, scheduler.getStudents());
       assertEquals(Arrays.asList(new Course[] {b}), scheduler.getCourses());
       assertTrue(a.getRoster().isEmpty());
       assertTrue(b.getRoster().isEmpty());
   }
  
   @Test
   public void testPreferFirst() {      
       Student s = new Student("s", 1, listAB);
       List<Student> listS = Arrays.asList(new Student[] {s});
      
       scheduler.addStudent(s);
       scheduler.addCourse(a);
       scheduler.addCourse(b);
       scheduler.assignAll();
      
       assertEquals(listS, scheduler.getStudents());
       checkList(listAB, scheduler.getCourses());
       assertEquals(listS, a.getRoster());
       assertEquals(listA, s.getSchedule());
       assertTrue(b.getRoster().isEmpty());
   }

   @Test
   public void testPreferSecond() {      
       Student s = new Student("s", 1, listBA);
       List<Student> listS = Arrays.asList(new Student[] {s});
      
       scheduler.addStudent(s);
       scheduler.addCourse(b);
       scheduler.addCourse(a);
       scheduler.assignAll();
      
       assertEquals(listS, scheduler.getStudents());
       checkList(listBA, scheduler.getCourses());
       assertEquals(listS, b.getRoster());
       assertEquals(listB, s.getSchedule());
       assertTrue(a.getRoster().isEmpty());
   }
  
   @Test
   public void testAddTwo() {      
       Student s = new Student("s", 2, listAB);
       List<Student> listS = Arrays.asList(new Student[] {s});
      
       scheduler.addStudent(s);
       scheduler.addCourse(b);
       scheduler.addCourse(a);
       scheduler.assignAll();
      
       assertEquals(listS, scheduler.getStudents());
       checkList(listBA, scheduler.getCourses());
       assertEquals(listS, a.getRoster());
       assertEquals(listS, b.getRoster());
      
       assertEquals(2, s.getSchedule().size());
       checkList(listAB, s.getSchedule());
   }
  
   @Test
   public void testAddOnlyOne() {      
       Student s = new Student("s", 1, listAB);
       List<Student> listS = Arrays.asList(new Student[] {s});
      
       scheduler.addStudent(s);
       scheduler.addCourse(b);
       scheduler.addCourse(a);
       scheduler.assignAll();
      
       assertEquals(listS, scheduler.getStudents());
       checkList(listBA, scheduler.getCourses());
       assertEquals(listS, a.getRoster());
       assertTrue(b.getRoster().isEmpty());
       assertEquals(listA, s.getSchedule());
   }
  
   @Test
   public void testTwoInTwo() {      
       Student s = new Student("s", 2, listAB);
       Student t = new Student("t", 2, listBA);
       List<Student> listST = Arrays.asList(new Student[] {s, t});
       List<Student> 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 testDropFromOne() {      
       Student s = new Student("s", 2, listAB);
       Student t = new Student("t", 2, listBA);
       List<Student> listST = Arrays.asList(new Student[] {s, t});
       List<Student> listTS = Arrays.asList(new Student[] {t, s});
      
       scheduler.addStudent(s);
       scheduler.addStudent(t);
       scheduler.addCourse(a);
       scheduler.addCourse(b);
       scheduler.assignAll();
       scheduler.drop(t, a);
      
       checkList(listST, scheduler.getStudents());
       checkList(listAB, scheduler.getCourses());
       assertEquals(Arrays.asList(new Student[] {s}), a.getRoster());
       checkList(listTS, b.getRoster());
       checkList(listAB, s.getSchedule());
       assertEquals(listB, t.getSchedule());
   }
  
   @Test
   public void testUnenrollOne() {      
       Student s = new Student("s", 2, listAB);
       Student t = new Student("t", 2, listBA);
       List<Student> 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());
   }
  
   @Test
   public void testOneFull() {      
       Student s = new Student("s", 2, listAC);
       Student t = new Student("t", 2, listCA);
       List<Student> listT = Arrays.asList(new Student[] {t});
       List<Student> listST = Arrays.asList(new Student[] {s, t});
       List<Student> listTS = Arrays.asList(new Student[] {t, s});
      
       scheduler.addStudent(t);
       scheduler.addStudent(s);
       scheduler.addCourse(c);
       scheduler.addCourse(a);
       scheduler.assignAll();
      
       checkList(listTS, scheduler.getStudents());
       checkList(listCA, scheduler.getCourses());
       checkList(listST, a.getRoster());
       assertEquals(listT, c.getRoster());
       assertEquals(listA, s.getSchedule());
       checkList(listCA, t.getSchedule());
   }
  
   @Test
   public void testOtherFull() {      
       Student s = new Student("s", 2, listAC);
       Student t = new Student("t", 2, listCA);
       List<Student> listT = Arrays.asList(new Student[] {t});
       List<Student> listST = Arrays.asList(new Student[] {s, t});
       List<Student> 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 testThree() {
       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();
      
       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[] {s, t}), 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, s}), d.getRoster());
       checkList(Arrays.asList(new Student[] {t, u}), e.getRoster());
       checkList(Arrays.asList(new Course[] {a, b, d}), s.getSchedule());
       checkList(Arrays.asList(new Course[] {c, a, e}), t.getSchedule());
       checkList(Arrays.asList(new Course[] {b, d, e}), u.getSchedule());
   }
  
   @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());
   }
}


Course.java


import java.util.ArrayList;
import java.util.List;

public class Course {
   private String courseNumber;
   private int capacity;
   private List<Student> roster;
  
   public Course(String courseNumber, int capacity) throws IllegalArgumentException {
       if (courseNumber.isEmpty() == true || capacity <= 0) {
           throw new IllegalArgumentException();
       }
       this.courseNumber = courseNumber;
       this.capacity = capacity;
       this.roster = new ArrayList<Student>();
   }
  
   /**
   *
   * @return the capacity of the course
   */
   public int getCapacity() {
       return capacity;
   }
  
   /**
   *
   * @return the course number
   */
   public String getCourseNumber() {
       return courseNumber;
   }

   /**
   * Returns the list of students enrolled in the course.
   *
   * This returned object does not share state with the internal state of the Course.
   *
   * @return the list of students currently in the course
   */
   public List<Student> getRoster() {
       List<Student> listed = new ArrayList<Student>(roster);
       return listed;
   }
  
   public void enroll(Student name) {
       roster.add(name);
   }
  
   public void kickStudent(Student name) {
       roster.remove(name);
   }
}


Scheduler.java


import java.util.ArrayList;
import java.util.List;

public class Scheduler {
  
   private List<Course> listOfCourses;
   private List<Student> listOfStudents;
  
   /**
   * Instantiates a new, empty scheduler.
   */
   public Scheduler() {
       listOfCourses = new ArrayList<Course>();
       listOfStudents = new ArrayList<Student>();
   }
  
   /**
   * Adds a course to the scheduler.
   *
   * @param course the course to be added
   */
   public void addCourse(Course course) {
       listOfCourses.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<Course> getCourses() {
       List<Course> courseList = new ArrayList<Course>(listOfCourses);
       return courseList;
   }
  
   /**
   * Adds a student to the scheduler.
   *
   * @param student the student to add
   */
   public void addStudent(Student student) {
       listOfStudents.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<Student> getStudents() {  
       List<Student> studentList = new ArrayList<Student>(listOfStudents);
       return studentList;
   }
   public void assignAll() {
       Student johnOrJaneDoe;
       Course desiredCourse;
       Course backUpChoice;
       int times = 0;
       for(int i = 0; i < listOfStudents.size(); i++) {
           if(listOfStudents.get(i).getPreferences().size() > times) {
               times = listOfStudents.get(i).getPreferences().size();
           }
       }
       while(true) {
           for(int i = 0; i < times; i++) {
               for(int st = 0; st < listOfStudents.size(); st++) {
                   johnOrJaneDoe = listOfStudents.get(st);
                   desiredCourse = johnOrJaneDoe.getPreferences().get(i);
                   if(johnOrJaneDoe.getMaxCourses() > johnOrJaneDoe.getSchedule().size()) {
                       if(listOfCourses.contains(desiredCourse)) {
                           if(desiredCourse.getRoster().contains(johnOrJaneDoe) == false) {
                               if(desiredCourse.getRoster().size() < desiredCourse.getCapacity()) {
                                   johnOrJaneDoe.addClass(desiredCourse);
                                   desiredCourse.enroll(johnOrJaneDoe);
                               }
                               else {
                                   for(int rip = i; rip < johnOrJaneDoe.getPreferences().size(); rip++) {
                                       backUpChoice = johnOrJaneDoe.getPreferences().get(rip);
                                       if(listOfCourses.contains(backUpChoice)) {
                                           if(backUpChoice.getRoster().contains(johnOrJaneDoe) == false) {
                                               if(backUpChoice.getRoster().size() < backUpChoice.getCapacity()) {
                                                   johnOrJaneDoe.addClass(backUpChoice);
                                                   backUpChoice.enroll(johnOrJaneDoe);
                                                   break;
                                               }
                                           }
                                       }
                                   }
                               }
                           }
                       }
                   }
               }
           }
           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 {
       if(listOfStudents.contains(student) == false || listOfCourses.contains(course) == false) {
           throw new IllegalArgumentException();
       }
       student.dropClass(course);
       course.kickStudent(student);
   }
  
   /**
   * 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(listOfStudents.contains(student) == false) {
           throw new IllegalArgumentException();
       }
       student.useless();
       for(int i = 0; i < listOfCourses.size(); i++) {
           if(listOfCourses.get(i).getRoster().contains(student)) {
               listOfCourses.get(i).kickStudent(student);
           }
       }
   }
}

Student.java

import java.util.ArrayList;
import java.util.List;
public class Student {
   private String name;
   private int maxCourses;
   private List<Course> preferences;
   private List<Course> schedule;
   private List<Course> timeTable;

  
   public Student(String name, int maxCourses, List<Course> preferences) throws IllegalArgumentException {
       if(name.isEmpty() == true || maxCourses <= 0 || preferences.size() < 1) {
           throw new IllegalArgumentException();
       }
       this.name = name;
       this.maxCourses = maxCourses;
       this.preferences = preferences;
       this.schedule = new ArrayList<Course>();
   }
  
   /**
   *
   * @return the student's name
   */
   public String getName() {
       return name;
   }
  
   /**
   *
   * @return the student's max course load
   */
   public int getMaxCourses() {
       return maxCourses;
   }
  
   /**
   * Returns the student's list of course preferences, ordered from most- to least-desired.
   *
   * This returned object does not share state with the internal state of the Student.
   *
   * @return the student's preference list
   */
   public List<Course> getPreferences() {
       return preferences;
   }
  
   /**
   * Returns the student's current schedule.
   *
   * This returned object does not share state with the internal state of the Student.
     *
   * @return the student's schedule
   */
   public List<Course> getSchedule() {
       timeTable = new ArrayList<Course>(schedule);
       return timeTable;
   }
  
   public void addClass(Course courseName) {
       schedule.add(courseName);
   }
  
   public void dropClass(Course courseName) {
       schedule.remove(courseName);
   }
  
   public void useless() {
       schedule.clear();
   }
}

Add a comment
Know the answer?
Add Answer to:
I need some help fixing this error. I completed the code, just modify it so the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • public class Scheduler {    private List<Course> classes;    private List<Student> students;    public Scheduler() {...

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

  • DO NOT COPY AND PASTED!!!!!!!!!!!!! IF YOU DO NOT HOW TO DO IT, JUST DO NOT...

    DO NOT COPY AND PASTED!!!!!!!!!!!!! IF YOU DO NOT HOW TO DO IT, JUST DO NOT ANSWER MY QUESTIONS package scheduler; import java.util.List; public class Scheduler { /** * Instantiates a new, empty scheduler. */ public Scheduler() { } /** * Adds a course to the scheduler. * * @param course the course to be added */ public void addCourse(Course course) { } /** * Returns the list of courses that this scheduler knows about. * * This returned object...

  • package scheduler; import java.util.List; public class Scheduler { /** * Instantiates a new, empty scheduler. */...

    package scheduler; import java.util.List; public class Scheduler { /** * Instantiates a new, empty scheduler. */ public Scheduler() { } /** * Adds a course to the scheduler. * * @param course the course to be added */ public void addCourse(Course 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 */...

  • I need help in converting this into pseudo-code Student.java public class Student implements Comparable<Student>{ private String...

    I need help in converting this into pseudo-code Student.java public class Student implements Comparable<Student>{ private String name, major, status; private int rank;    public Student() { this.name = this.major = this.status = ""; this.rank = 0; }    public Student(String name, String major, String status) { this.name = name; this.major = major; this.status = status; } public String getName() { return name; } public String getMajor() { return major; } public String getStatus() { return status; }    public int...

  • I need help fixing my java code for some reason it will not let me run...

    I need help fixing my java code for some reason it will not let me run it can someone pls help me fix it. class LinearProbingHashTable1 { private int keyname; private int valuename; LinearProbingHashTable1(int keyname, int valuename) { this.keyname = keyname; this.valuename = valuename; } public int getKey() { return keyname; } public int getValue() { return valuename; } } class LinearProbingHashTable2 { private final static int SIZE = 128; LinearProbingHashTable2[] table; LinearProbingHashTable2() { table = new LinearProbingHashTable2[SIZE]; for (int...

  • java programming how would i modify the code below to add a GUI (with a main menu with graphics and buttons, etc...) and include an option to print a list of all students added in a grid format and sh...

    java programming how would i modify the code below to add a GUI (with a main menu with graphics and buttons, etc...) and include an option to print a list of all students added in a grid format and short by name, course, instructor, and location. ///main public static void main(String[] args) { Scanner in = new Scanner(System.in); ArrayList<Student>students = new ArrayList<>(); int choice; while(true) { displayMenu(); choice = in.nextInt(); switch(choice) { case 1: in.nextLine(); System.out.println("Enter Student Name"); String name...

  • Need some assistance coding this assembler exercise. I have included the test file. Thank you very...

    Need some assistance coding this assembler exercise. I have included the test file. Thank you very much. package sequencer; import java.util.List; public class Assembler {    /**    * Creates a new Assembler containing a list of fragments.    *    * The list is copied into this assembler so that the original list will not    * be modified by the actions of this assembler.    *    * @param fragments    */    public Assembler(List<Fragment> fragments) {   ...

  • I asked this a little bit ago but didn't clarify exactly what I needed, so I'm...

    I asked this a little bit ago but didn't clarify exactly what I needed, so I'm asking again...I've attached my code below the question. Thanks! Do not change the original contract of the Course class. Instead, ONLY change the implementation of property students, from an array to and ArrayList, and update any methods in class Course that access students to reflect ArrayList. The methods are overridden. That means that you do not need to change the header for methods, only...

  • Please help complete the items marked TODO in the code and get the tests to pass:...

    Please help complete the items marked TODO in the code and get the tests to pass: import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; public class TestPerformance { // TODO run test and record running times for SIZE = 10, 100, 1000, 10000, ... // (choose in conjunction with REPS below up to an upper limit where the clock // running time is in the tens of seconds) // TODO (optional) refactor to DRY // TODO...

  • Please help complete the items marked TODO in the code and get the tests to pass:...

    Please help complete the items marked TODO in the code and get the tests to pass: Someone already answered it, but it was incorrect! import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; public class TestPerformance { // TODO run test and record running times for SIZE = 10, 100, 1000, 10000, ... // (choose in conjunction with REPS below up to an upper limit where the clock // running time is in the tens of seconds)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT