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 does not share state with the internal state of the Scheduler.
*
* @return the list of courses
*/
public List<Course> getCourses() {
return null;
}
/**
* Adds a student to the scheduler.
*
* @param student the student to add
*/
public void addStudent(Student 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() {
return null;
}
/**
* 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() {
}
/**
* 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 {
}
/**
* 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{
}
}
---------------------------------------------------------------------
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<Course> 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<Course> 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<Course> getSchedule() {
return null;
}
}
---------------------------------------------------------------------------
package scheduler;
import java.util.List;
/**
* A class representing a Course.
*
* @author liberato
*
*/
public class Course {
/**
* Instantiates a new Course object. The course number must be non-empty, and the
* capacity must be greater than zero.
* @param courseNumber a course number, like "COMPSCI190D"
* @param capacity the maximum number of students that can be in the class
* @throws IllegalArgumentException thrown if the courseNumber or capacity are invalid
*/
public Course(String courseNumber, int capacity) throws IllegalArgumentException {
}
/**
*
* @return the capacity of the course
*/
public int getCapacity() {
return -1;
}
/**
*
* @return the course number
*/
public String getCourseNumber() {
return null;
}
/**
* 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() {
return null;
}
}
Here is the complete solution. You can directly create all the 4 of the below mentioned classes in any java IDE and paste the respective code then you can check the solution as well. I have added a Demo class to check the functioning of the program.
The required classes are
1) Course.java
2) Student.java
3) Scheduler.java
4) Demo.java - contains the main function to test the functioning of the classes.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
1) Course.java
import java.util.ArrayList;
import java.util.List;
/**
* A class representing a Course.
*
* @author liberato
*
*/
public class Course {
/**
* Instantiates a new Course object. The course number must be non-empty, and the
* capacity must be greater than zero.
* @param courseNumber a course number, like "COMPSCI190D"
* @param capacity the maximum number of students that can be in the class
* @throws IllegalArgumentException thrown if the courseNumber or capacity are invalid
*/
//Data Members
String courseNumber;
int capacity;
List<Student> students = new
ArrayList<Student>();
public Course(String courseNumber, int capacity) throws IllegalArgumentException {
if(courseNumber!=null &&
capacity>0)
{
this.courseNumber = courseNumber;
this.capacity = capacity;
}
else
throw new
IllegalArgumentException();
}
/**
*
* @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() {
return students;
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
2) Student.java
import java.util.ArrayList;
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
*/
//Data members
String name;
int maxCourses;
List<Course> preferences = new
ArrayList<Course>();
List<Course> courses = new ArrayList<Course>();
public Student(String name, int maxCourses, List<Course>
preferences) throws IllegalArgumentException {
if(maxCourses>0 &&
preferences!=null)
{
this.name = name;
this.maxCourses = maxCourses;
this.preferences = preferences;
}
else
throw new
IllegalArgumentException();
}
/**
*
* @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() {
return courses;
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
3)Scheduler.java
import java.util.ArrayList;
import java.util.List;
public class Scheduler {
/**
*
* Instantiates a new, empty scheduler.
*
*/
// Data members
List<Course> courses = new
ArrayList<Course>();
List<Student> students = new
ArrayList<Student>();
public Scheduler() {
}
/**
*
* Adds a course to the scheduler.
*
*
*
* @param course
* the course to be added
*
*/
public void addCourse(Course course) {
if(!courses.contains(course))
courses.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() {
return courses;
}
/**
*
* Adds a student to the scheduler.
*
*
*
* @param student
* the student to add
*
*/
public void addStudent(Student student) {
if(!students.contains(student))
students.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() {
return students;
}
/**
*
* 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() {
boolean notOver = false; // to
check if all the conditions are over
while (true) {
notOver =
false;
for (Student s :
students) {
if (s.getSchedule().size() < s.maxCourses) //
if max number of course for student has not exceeded
{
for (Course c :
s.getPreferences()) {
if
(courses.contains(c) && !c.getRoster().contains(s)
&& c.capacity > c.getRoster().size()) // if the course
does not
// contain
this student
// and
capacity is left
{
c.getRoster().add(s);
s.getSchedule().add(c);
notOver = true;
break;
}
}
}
}
if(!notOver)
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(students.contains(student)
&& courses.contains(course))
{
student.getSchedule().remove(course);
course.getRoster().remove(student);
}
else
{
throw new
IllegalArgumentException();
}
}
/**
*
* 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))
{
student.getSchedule().clear();
for (Course c :
courses) {
if(c.getRoster().contains(student))
{
c.getRoster().remove(student);
}
}
}
else
{
throw new
IllegalArgumentException();
}
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
4) Demo.java
import java.util.ArrayList;
import java.util.List;
public class Demo {
public static void main(String[] args) {
Course c1 = new Course("C1",1);
Course c2 = new Course("C2",2);
Course c3 = new Course("C3",3);
List<Course> p1 = new
ArrayList<Course>();
p1.add(c1);p1.add(c2);p1.add(c3);
Student s1 = new
Student("Alex",2,p1);
Student s2 = new
Student("Bob",3,p1);
Student s3 = new
Student("Charlie",1,p1);
Scheduler s = new
Scheduler();
s.addCourse(c1);s.addCourse(c2);s.addCourse(c3);
s.addStudent(s1);s.addStudent(s2);s.addStudent(s3);
s.assignAll();
System.out.println("--------Courses
Per Student----------");
for (Student stud :
s.getStudents()) {
System.out.print(stud.getName()+":");
for (Course c :
stud.getSchedule()) {
System.out.print(c.getCourseNumber()+" ");
}
System.out.println();
}
System.out.println("--------Students Per Course----------");
for (Course c : s.getCourses()) {
System.out.print(c.getCourseNumber()+":");
for (Student
stud : c.getRoster()) {
System.out.print(stud.getName()+" ");
}
System.out.println();
}
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
The output on running Demo.class would be as follows:
--------Courses Per Student----------
Alex:C1 C3
Bob:C2 C3
Charlie:C2
--------Students Per Course----------
C1:Alex
C2:Bob Charlie
C3:Alex Bob
--------------------------------------------------------------------------------------------------------------------------------------------------------------
You can comment if you need any more help!
DO NOT COPY AND PASTED!!!!!!!!!!!!! IF YOU DO NOT HOW TO DO IT, JUST DO NOT...
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 */...
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); } ...
How to complete this methods: import java.io.FileInputStream; import java.io.FileNotFoundException; import java.time.LocalDate; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Scanner; import java.util.Set; /** * Utility class that deals with all the other classes. * * @author EECS2030 Summer 2019 * */ public final class Registrar { public static final String COURSES_FILE = "Courses.csv"; public static final String STUDENTS_FILE = "Students.csv"; public static final String PATH = System.getProperty("java.class.path"); /** * Hash table to store the list of students using their...
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 =...
How to complete these methods: /** * Returns a reference to the course with title equals to the argument. This * method searches in the courses stored in the HashMap {@code courses} to find * the course whose title equals to the argument {@code title}. If the course is * not found, {@code null} is returned. * * @param title the title of the course * @return a reference to the course, or {@code null} if the course is not ...
package model; import java.util.Iterator; /** * This class implements interface PriorityList<E> to represent a generic * collection to store elements where indexes represent priorities and the * priorities can change in several ways. * * This collection class uses an Object[] data structure to store elements. * * @param <E> The type of all elements stored in this collection */ // You will have an error until you have have all methods // specified in interface PriorityList included inside this...
Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src folder, create a package named: edu.ilstu · Import the following files from T:\it168\Labs\lab13. Note that the .txt file must be in the top level of your project, not inside your src folder. o Student.java o StudentList.java o students.txt Carefully examine the Student.java and StudentList.java files. You are going to complete the StudentList class (updating all necessary Javadoc comments), following the instruction in the code....
Java help: Please help complete the locate method that is in bold.. public class LinkedDoubleEndedList implements DoubleEndedList { private Node front; // first node in list private Node rear; // last node in list private int size; // number of elements in list ////////////////////////////////////////////////// // YOU MUST IMPLEMENT THE LOCATE METHOD BELOW // ////////////////////////////////////////////////// /** * Returns the position of the node containing the given value, where * the front node is at position zero and the rear node is...
1. the path length of a binary tree BT is the sum of the depths of all position in BT. write and test a linear-time java method for computing the path length of a binary tree BT. add the method to linkedbinarytree class and write testing code in main method. hint: add method to linkedbinarytree class and write testing in main method public class LinkedBinaryTree<E> extends AbstractBinaryTree<E> { //---------------- nested Node class ---------------- /** Nested static class for a binary...
Copy the program AmusementRide.java to your computer and add your own class that extends class AmusementRide. Note: AmusementRide.java contains two classes (class FerrisWheel and class RollerCoaster) that provide examples for the class you must create. Your class must include the following. Implementations for all of the abstract methods defined in abstract class AmusementRide. At least one static class variable and at least one instance variable that are not defined in abstract class AmusementRide. Override the inherited repair() method following the...