Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need some help coding this file. The Student class represents a single student, their maximum course load, and a list of courses the student

I need some help coding this file. The Student class represents a single student, their maximum course load, and a list of courses the student would like (in order of preference, most-preferred-to-least). I have included the tests. Thank you!

package scheduler;

import java.util.List;

/**

* A class representing a student.

*

* @author liberato

*

*/

public class Student {

/**

*

* Instantiates a new Student object. The student's maximum course load must be greater

* than zero, and the preferences list must contain at least one course.

*

* The preference list is copied into this Student object.

*

* @param name the student's name

* @param maxCourses the maximum number of courses that can be on this student's schedule

* @param preferences the student's ordered list of preferred courses

* @throws IllegalArgumentException thrown if the maxCourses or preferences are invalid

*/

public Student(String name, int maxCourses, List preferences) throws IllegalArgumentException {

}

/**

*

* @return the student's name

*/

public String getName() {

return null;

}

/**

*

* @return the student's max course load

*/

public int getMaxCourses() {

return -1;

}

/**

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

return null;

}

/**

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

return null;

}

}

StudentTest.java

package scheduler;

import org.junit.Test;

import static org.junit.Assert.*;

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

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

public class StudentTest {

// uncomment the following if you're trying to diagnose an infinite loop in a test // @Rule // public Timeout globalTimeout = Timeout.seconds(10); // 10 seconds

private Student joe; private List courseList; // This method is run before each test, performing initialization // on objects for the test. @Before public void setup() { courseList = new ArrayList<>(); courseList.add(new Course("COMPSCI190D", 120)); courseList.add(new Course("MATH132", 50)); courseList.add(new Course("ENGLWRIT112", 20)); joe = new Student("Joe", 4, courseList); } @Test public void testGetName() { assertEquals("Joe", joe.getName()); }

@Test public void testGetMaxCourses() { assertEquals(4, joe.getMaxCourses()); }

@Test public void testGetPreferences() { assertEquals(courseList, joe.getPreferences()); }

@Test public void testGetPreferencesNotShared() { List prefs = joe.getPreferences(); prefs.clear(); assertEquals(courseList, joe.getPreferences()); } @Test public void testGetScheduleEmpty() { assertTrue(joe.getSchedule().isEmpty()); }

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

@Test(expected = IllegalArgumentException.class) public void testInvalidMaxCourses() { Student s = new Student("NoCourses", 0, courseList); }

@Test(expected = IllegalArgumentException.class) public void testEmptyPreferences() { Student s = new Student("DontCare", 3, new ArrayList()); } }

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions