Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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.

2. Write a fully-docund class named Plana which stores an ordered list of Course objscts. Tha array indiees detarmine the preference of the courses (do uot use Array List, Vector, or any other Java API Data Struchmres), A stadent can insert a course at any position within the ranze of the list. Make sure there are no gaps betmeen courses on the list. Note that arrays in Java are0 indexed, but your listing preference shoald start from 1. The Flanner cam record a total of 50 coures, so use the inal rariable MAX DOURSES 60 (and refrain from using the aumber 30 within yoar codeThe daas will be based on tha tollowig ADT specifieation: publio class lanner The Planner class implemota an abstract data type for a list of cours supporting som. eoninoa operatius on such lists. pablie Plannar Constructs an instauce of the Planne with no Coarse objects in it. This Planner has been initialized to au empty list of Courses . publtio int s1zc newcourse thc new coursc to add to thc List This Course object has be instantiated and 1 position items curreatty in list i 1. The number of Course obests in this Planner is less than 3LLX COURSES. 5 Courses in a Planner, positioned 1 .and you insert a Course in position 4, the new Course Troald bc placed in positiou 4, position 5, and the Course that was in position 5 mill be mved to position 6) Turows c Course that Tras in position 4 mn be moved to KIH 1.1 cm r. er, lo tlin positi"" "' thr Planner and "n4111Hjulutinn in the array. Nore 1: inserting an item in position (itcms currently in list i l) ffectively the sans as adding the item to the end of the list. Works just likeli void adi(Cor None newCour, int position), exept adds tn the end of the list This mechod can be Titteu in oe line using the addcourse) and sizc() mcthods above ublis void renoveCourt osition! position the positiou in the Plauner where the Coarsa will be removed fro This Planner has been instantiated and 1Sposition Sitems currently_in_list The Course at the desired positios has been rmoved. All Courses that were originally greatar than or equal to position are mored backward one position. (.g. If there are3 Coarses in a Planner, positioned 1-5, and yoemove the Couse in position 4, the item that as in position 5 will be moved to position 4.) Trows: IllegalargunetException Indicates that position is not within tha vald range Note position refers to the position in the Planner and not the position in the array pablie coursa gatcoursa int position) position position of the Course to retriee. The Planner object has boen instantiated and Spaaitionitems eurreyly in ist The Course at the speciied position in this Plauner object. arows IllcgalargunentException Indicatea thapaaitiais nt within the vaid rang None position refers to the positiou in the Plauner aud not the position in the array. -putli atat.ic voil filtHriPlannr plr, it.ring artnt Trints all Courses that are mithin the speciitd department. Parametes planner the list of courses to search in This Planne objet has been instautiated. Displays a neatly formatted table of each conse filtered from the laner. Keep the preference numbers the same. This lanner aud Coursc has both been instautiated True is thc Manur comtains this Con, false othcrwisc. This Planner hjert ha ben ins antiatnd. Returns eup? (harkup)oihis Planner ohjeet. Priats a neatly formated table of each irc ia the listnit its position namber as shown in the sample output. This Planner has been instautiatod Displats a aeatly formatted table of each course from the Paaner Hiat: Ifyour tostring) method is mplemcuted correctly as dascribed below, you will sinsply weed to call it aud priat the results to the user. Gets the String representation of this Planer object, whicli is a neatly forlikatted table of each Course in the Plaaner 0 its own line with its positio number as showin the sample The String represcntation of this Planner object publis string tostring( utput. Renaes

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

Advances In Databases 11th British National Conference On Databases Bncod 11 Keele Uk July 7 9 1993 Proceedings Lncs 696

Authors: Michael F. Worboys ,Anna F. Grundy

1993rd Edition

3540569219, 978-3540569213

More Books

Students also viewed these Databases questions

Question

What is Aufbau's rule explain with example?

Answered: 1 week ago

Question

Write Hund's rule?

Answered: 1 week ago

Question

Enhance the basic quality of your voice.

Answered: 1 week ago

Question

Describe the features of and process used by a writing team.

Answered: 1 week ago