Question: . Write a fully-documented class named Planner which stores an ordered list of Course objects. The array indices determine the preference of the courses (do

. Write a fully-documented class named Planner which stores an ordered list of Course objects. The array indices determine the preference of the courses (do not use ArrayList, Vector, or any other Java API Data Structures). A student can insert a course at any position within the range of the list. Make sure there are no gaps between courses on the list. Note that arrays in Java are 0 indexed, but your listing preference should start from 1. The Planner can record a total of 50 courses, so use the final variable MAX_COURSES = 50 (and refrain from using the number 50 within your code). The class will be based on the following ADT specification:

public class Planner The Planner class implements an abstract data type for a list of courses supporting some common operations on such lists.

public Planner Constructs an instance of the Planner with no Course objects in it. Postcondition: This Planner has been initialized to an empty list of Courses.

public int size() Determines the number of courses currently in the list. Preconditions: This Planner has been instatiated. Returns: The number of Courses in this Planner.

public void addCourse(Course newCourse, int position) Parameters: newCourse - the new course to add to the list position - the position (preference) of this course on the list Preconditions: This Course object has been instantiated and 1 position items_currently_in_list + 1. The number of Course objects in this Planner is less than MAX_COURSES. Postconditions: The new Course is now listed in the correct preference on the list. All Courses that were originally greater than or equal to position are moved back one position. (e.g. If there are 5 Courses in a Planner, positioned 1-5, and you insert a Course in position 4, the new Course would be placed in position 4, the Course that was in position 4 will be moved to position 5, and the Course that was in position 5 will be moved to position 6.) Throws: IllegalArgumentException Indicates that position is not within the valid range. FullPlannerExpcetion Indicates that there is no more room in the Planner to record an additional Course. Note 1: position refers to the position in the Planner and not the position in the array. Note 2: Inserting an item in position (items_currently_in_list + 1) is effectively the same as adding the item to the end of the list.

public void addCourse(Course newCourse) Works just like public void addCourse(Course newCourse, int position), except adds to the end of the list. Note: This method can be written in one line using the addCourse() and size() methods above.

public void removeCourse(int position) Parameters: position - the position in the Planner where the Course will be removed from. Preconditions: This Planner has been instantiated and 1 position items_currently_in_list. Postconditions: The Course at the desired position has been removed. All Courses that were originally greater than or equal to position are moved backward one position. (e.g. If there are 5 Courses in a Planner, positioned 1-5, and you remove the Course in position 4, the item that was in position 5 will be moved to position 4.) Throws: IllegalArgumentException Indicates that position is not within the valid range. Note: position refers to the position in the Planner and not the position in the array.

public Course getCourse(int position) Parameters: position - position of the Course to retrieve. Preconditions: The Planner object has been instantiated and 1 position items_currenyly_in_list. Returns: The Course at the specified position in this Planner object. Throws: IllegalArgumentException Indicates that position is not within the valid range. Note: position refers to the position in the Planner and not the position in the array.

public static void filter(Planner planner, String department) Prints all Courses that are within the specified department. Parameters: planner - the list of courses to search in department - the 3 letter department code for a Course Preconditions: This Planner object has been instantiated. Postconditions: Displays a neatly formatted table of each course filtered from the Planner. Keep the preference numbers the same.

public boolean exists(Course course) Checks whether a certain Course is already in the list. Parameters: course - the Course we are looking for Preconditions: This Planner and Course has both been instantiated. Returns: True if the Planner contains this Course, false otherwise.

public Object clone() Creates a copy of this Planner. Subsequent changes to the copy will not affect the original and vice versa. Preconditions: This Planner object has been instantiated. Returns: A copy (backup) of this Planner object.

public void printAllCourses() Prints a neatly formatted table of each item in the list with its position number as shown in the sample output. Preconditions: This Planner has been instantiated. Postconditions: Displats a neatly formatted table of each course from the Planner. Hint: If your toString() method is implemented correctly as described below, you will simply need to call it and print the results to the user.

public String toString() Gets the String representation of this Planner object, which is a neatly formatted table of each Course in the Planner on its own line with its position number as shown in the sample output. Returns: The String representation of this Planner object

Support Class for referance:

import java.io.*; import java.util.Scanner; public class Course { public String courseName; public String department; public int code; public byte section; public String instructor; public Course() { } public void course(String courseName, String department, int code, byte section, String instructor){ this.courseName = courseName; this.department = department; this.code = code; this.section = section; this.instructor = instructor; } public String getCourseName(){ return courseName; } public void setCourseName(String courseName){ this.courseName = courseName; } public String getDepartment(){ return department; } public void setDepartment(String department){ this.department = department; } public int getCode(){ return code; } public void setCode(int code){ if (code <= 0){ throw new IllegalArgumentException("Enter a Positive number"); } this.code = code; } public byte getSection(){ return section; } public void setSection(byte section){ if (section < 0) { throw new IllegalArgumentException("Enter a Positive number"); } this.section = section; } public String getInstructor(){ return instructor; } public void setInstructor(String instructor){ this.instructor = instructor; } public Object clone() throws CloneNotSupportedException{ return super.clone(); } public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Course)) return false; Course course = (Course) o; if (code != course.code) return false; if (section != course.section) return false; if (courseName != null ? !courseName.equals(course.courseName) : course.courseName != null) return false; if (department != null ? !department.equals(course.department) : course.department != null) return false; return instructor != null ? instructor.equals(course.instructor) : course.instructor == null; } } 

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!