Question: Course This is a class that manages some information for courses. A Course is Comparable ( should be comparable to other Courses ) . It

Course
This is a class that manages some information for courses. A Course is Comparable (should be comparable to other Courses). It will have:
The following instance variables: id (String), name (String), creditHours (int). All attributes will never change and should be marked accordingly.
A private 3-arg constructor that takes all the instance variables in order and sets them.
A static Course fromID(String) method that creates an instance of a Course based on the information of a course in a file. It receives an id and looks up the course information in the file course-[id].txt (without square brackets). The file will have the course name in the first line and the course credits in the second line. If the course doesn't exist (because the file isn't present), the method should propagate a CourseDoesNotExistException with the appropriate message. Getters for all instance variables
An equals method. A Course is equal to another if they have the same id (as there aren't multiple courses with the same id but different name/creditHours)
A compareTo method. It should be such that courses can ordered by their id in ascending order.
Courseoffering
This is a class that manages some information for course offerings. A Course0ffering is Comparable (should be comparable to other CourseOfferings). It will have:
The following instance variables: id (String), course (Course), semester (String), occupiedSeats (int), totalSeats (int). All attributes except occupiedSeats will never change and should be marked accordingly.
The following class variables: courseOfferingsFile (File), courseofferings (Courseoffering []). The first should be initialized to null, and the second should be initialized to a 0-length CourseOffering array.
A private 5-arg constructor that takes all the instance variables in order and sets them.
A static void loadCourseofferings(File) method that takes a file and sets the class variables. The file will be a CSV file (without a header row) such that each line is formatted "id, courseID, semester, occupiedSeats, totalSeats" (without quotation marks), and it is guaranteed that none of the String values will have a comma.
As soon as the method starts executing, set courseOfferingsfile to the passed parameter and course0fferings to a 0-length array, which will be the resulting state of the class variables if the method throws an exception.
After that, attempt to retrieve the information of all courses (including creating Course instances from the courseID), producing an array with all the course offerings. You will then sort the array and store it in course0fferings. If the file doesn't exist, propagate a FileNotFoundException.
Note 1: even if many CourseOfferings share courseID, you should still create multiple instances of Course for them - don't cache an instance. Additionally, it's acceptable to read the course information file multiple times for that courseID. In short: you should not apply any optimizations to speed up the loading process.
, Note 2: There are two main approaches to loading the file, and both are equally acceptable. Both of these treat the difficulty imposed by the fact that arrays have a fixed length. In L17, we will learn about a better way to handle an ordered sequence of elements (which can change in size)
Approach 1: scan the file once to know how many offerings there are, create the array with the correct length, and then scan it again to create the instances. Make sure to close the first Scanner before creating another for the same File.
Approach 2: scan the file only once, and each time you create a new offering, create a new array with an increased length, copy the offerings already parsed, and put the new one at the end
A static void saveCourseOfferings () method that writes the CourseOfferings from courseofferings to the File in courseOfferingsFile, using the format described for the loading method. This method should propagate
FileNotFoundException (as PrintWriter can throw it in some scenarios, such as failure to create the file) and IllegalStateException (this is an unchecked exception in the Java API and doesn't need to be imported since it's in java.lang)
If courseOfferingsFile is null, throw an IllegalStateException with the message "The course offerings are not loaded"
Note: the file should end in a single newline after the last course offering information, except when the file is empty because there are no course offerings.
A static Courseoffering getCourseoffering(String) method that returns a CourseOffering by looking for the course offering id in courseOfferings. The method should throw a CourseOfferingDoesNotExistException with the appropriate message if the course offering doesn't exist.
Note: this method should execute the lookup quickly, in 0(logn) time for n course offerings. We reserve the right to manually deduct points if the implementation does a linear search
Course This is a class that manages some

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 Accounting Questions!