Java代写 | CPS209 Assignment 2: Extended Student Registry Simulator

本次Java代写是扩展Student Registry Simulator程序

CPS209 Assignment 2:

Extended Student Registry Simulator

Program Functionality Requirements:

Please look at the video included with this assignment. Below is a description of the new class for your assignment and some new methods and other modifications. NOTE: I would like you to extend your assignment 1 (A1) and keep the classes essentially as they were except for changes and additions specified below. I strongly suggest you build your program in pieces. Get one piece compiled and working before working on the next piece. Read the marking scheme below and use it as a guide. You are permitted to add other instance variables and other methods if you think they are necessary.

NOTE WELL!!: if you want to extend my solution to assignment 1, then I will post it by early next week, once everyone has handed in their assignment 1.

 

1.  ActiveCourse: Add new instance variables int lectureStart, int lectureDuration, String lectureDay. You can use different names if you prefer. These variables will be set/used by the new Scheduler class.

2.  Registry: There are several changes and additions to the Registry class:

 

a.  Change the constructor method so that the student names and ids are read from a file called students.txt. I suggest you create a helper method that reads this file one line at a time. Each line should contain the student name and id. You will have to handle IOExceptions. Catch Exceptions in the main method by surrounding the lines Registry registry = new Registry(); by a try{..} catch{..} block. Once you have read a student name and id from the file, proceed as usual – create a Student object and add it to the TreeMap (or ArrayList if you are not able to convert to a TreeMap).

b.  Change both array lists students and courses to TreeMap rather than ArrayList. Use the student id as the key for the students TreeMap and use the course code as the key for the courses TreeMap. You will then have to modify the code in several of the methods of class Registry to use a Map rather than an ArrayList. Study the Collections lecture slides for Maps and Sets. I will be posting a lecture presentation with audio sometime this week which will help you.

3.  Add a new class Scheduler. This class is responsible for scheduling active courses. There will be 3 new commands added to the StudentRegistrySimulator that use the Scheduler. These 3 new commands will be explained in point 4. below. A minimal amount of skeleton code has been provided for you for Scheduler. Here are some suggested public methods for this class (note – add any other helper methods or variables you think you need):

a.  public Scheduler(TreeMap<String,ActiveCourse> courses). A constructor method that takes a reference to a TreeMap of active courses. In the main method of class StudentRegistrySimulator, after you have created a Registry object, you should create a Scheduler object and pass in the courses (formerly an ArrayList of ActiveCourse) treemap from the registry. Initialize the schedule instance variable. See the skeleton code. This constructor method has been written for you.

b.  public void setDayAndTime(String courseCode, String day, int startTime, int duration). Given a courseCode and other parameters, this method will set the variables lectureDay, lectureStart, lectureDuration of the corresponding active course object. However, this method does extensive error checking first before setting these variables. If there is an error in one of the parameters, then this method should throw an appropriate exception. These exceptions should be caught in the main method of class StudentRegistrySimulator. I suggest you create your own custom exceptions by extending RuntimeException (see the example in the lecture slides). Here is the error checking this method should support

·   UnknownCourse exception: the given courseCode cannot not be found

·   InvalidDay exception: the string parameter day should be one of “Mon”, “Tue”, “Wed”, “Thur”, “Fri”.

·   InvalidTime exception: the startTime parameter should not be less than 0800 (8 am) and the end time of the lecture (based on the duration parameter) should not be greater than 1700 (5pm). Use a 24 hour clock.

·   InvalidDuration parameter: the lecture duration should be 1, 2 or 3 hours.

·   LectureTimeCollision exception : the day, startTime, and duration should be such that it does not create any overlap with another scheduled course.

c.  public void clearSchedule(String courseCode). Given the course code, reset the lectureDay to “”, lectureStart to 0 and lectureDuration to 0 of the ActiveCourse object. If no such active course exists, do nothing.

d.  public void printSchedule(). See the video. Prints the timetable in a nice format. Feel free to make your formatting nicer than mine but it must be “2D” with hours along the left side and days across the top.

e.  NOTE: only allow a course to be scheduled for a single block of time during the week. If it is already scheduled, then just over write the current schedule. See the bonus below

4.  Modify class StudentRegistrySimulator. Add three new commands:

a.  “SCH courseCode day start duration”. See the video. For example: sch cps209 Mon 900 3. Schedules a course for a certain day, start time and duration. Don’t forget to catch any exceptions thrown. Print an appropriate message to the user if an exception is thrown.

b.  “CSCH courseCode”. Clears the schedule of the given course

c.  “PSCH” Prints the entire schedule.

 

5.  BONUS:

a.  Extend the scheduler to handle multiple blocks of time for a course during the week. For example, cps209 could have a 2 hour lecture on Fridays from 0800-1000 and a 1 hour lecture from 0900-1000 on Wednesdays.

b.  For ambitious students, make the scheduler more automatic. Given a course code and a lecture duration, the scheduler automatically finds a block of time during the week. If it cannot, it throws an exception. If it succeeds, when you print the schedule, you should see the course has been scheduled.

Grading (Out of 10 marks)

Highest Grade Possible: 12

 

File I/O and exception handling for reading the students.txt file and populating the registry with students 3 marks
Changing the array lists students and courses in Registry to TreeMaps and altering the methods appropriately in class Registry 2 marks
Scheduler implementation and 3 new commands 5 marks
Bonus a 1 mark
Bonus b 1 mark
Penalty for insufficient comments or bad program structure or bad use of exceptions, maps etc Up to -1 marks