Faculty of Computing and Information Technology

Faculty of Computing and Information Technology Computer Science Department CPCS204, 1 st Term 2016 Program 4: FCIT Class Registration Purpose: 1. Practice using stacks and queues. Read Carefully: ? This program is worth 6% of your final grade. ? WARNING: This is an individual project; you must solve it by yourself. Any form of cheating will result in receiving – 4% (less than zero) in the project. ? The deadline for this project is by 11:59 PM on Thursday, Nov 19th 2015. o Note: once the clock becomes 11:59PM, the submission will be closed! Therefore, in reality, you must submit by 11:58 and 59 seconds. ? LATE SUBMISSION: you are allowed to make a late submission, but there is a penalty. If you submit within 24 hours of the due date (so on Friday by 11:59PM), you will receive a 25% deduction. If you submit within 48 hours of the due date (so on Saturday by 11:59PM), you will receive a 50% deduction. ? Blackboard Submission: ? This project must be submitted online via blackboard ? The source file(s) of your program should be zipped up. You must name the zip file using the following naming convention: SectionNumber_StudentID_ProjectNumber.zip Example: EA_ 1110348_ P4.zip ? Discussions: ? We will randomly select a certain number of students for discussion for each project. ? If you are chosen for discussion, we will email you with a specific date/time. ? If you do not show up for discussion, you will get a -4 for the program. Program 4: FCIT Course Registration Objective Practice using stacks and queues. The Problem The online registration system is no longer working! In order to register for classes, all students must go to the Registration Lab (Lab 3A) and register on an official FCIT Registration Laptop. Before you can enter the Lab, you must wait in a LONG line...because all FCIT students are doing the same thing! Thankfully, registration is simple and easy, although it is VERY time consuming! Once a student reaches the front of the line, they must check-out (borrow) an official laptop to complete the registration (Registration will only work from these official laptops). Therefore, once a student reaches the front of the line, they will briefly interact with (talk to) an official FCIT Laptop Check-out Mudeer. This Mudeer will issue them a laptop (from a stack of laptops). Unfortunately, there are a limited number of official registration laptops! So not only must students wait in this excessively long laptop line, but even once at the front, they may have to wait for one of these laptops to become available. Once a student is issued a laptop, they will then spend exactly five minutes registering for classes. Once the five minutes are up, we assume that they student has finished their registration. The student must then get into a separate laptop return line. This line is ONLY for students who are returning laptops. Therefore, this line is a lot quicker than the laptop checkout line. Once students arrive at the front of the laptop return line, they briefly interact with (talk to) an official FCIT Laptop Return Mudeer. This Mudeer will print out a confirmation page for the student, and then he will place (PUSH) the laptop back on the stack of laptops. Finally, all registrations are saved in an alphabetical linked-list for the purpose of printing the FCIT Daily Registration Report. Your Assignment is to write a simulation that models the aforementioned Registration over n number of days, where the simulation runs over each minute of every day, from 12 PM to 5 PM. ? So this simulation is simply a FOR loop (or WHILE loop) that will iterate one time for each minute between 12PM and 5PM (and possibly longer if students are still in the lab registering…see details below) Implementation Details: To solve this program, you will need: ? three queues. (Note: each queue will contain objects of type FCITstudent object. Therefore, each queue will be an object of the same FCITqueue.java class.) ? one stack (for the laptops) ? one linked-list (to save all the daily registrations) The UML Diagrams for required Java classes are at the end of this write-up. Outside Line: For a given day, you will first read in, from a file, all the students that will ultimately arrive during that day. Students will be in chronological order in the file – i.e. the first student in the file will be first to enter the Registrar’s office. For each student you read, you must create a new object of type FCITstudent, save their appropriate (read-in) information into their student object, and then you will enqueue them into what we call the “outside line.” What is the “outside line”? The outside line (which is clearly a queue) will contain all of the students who are expected to come during that particular day. As time moves forward, you will remove (dequeue) students from the outside line IF the currentTime (your daily looping variable over each minute) equals the “arrival” time of the student who is at the front of the outside line. Once a student “arrives” at Lab 3A (is dequeued from the outside line), they enter the Lab and are immediately enqueued into the laptop waiting line. Note: it is possible that multiple students will “arrive” at Lab 3A at the same time. Meaning, multiple students can possibly have the same arrival time within the “outside line”. Students that arrive at the same time are placed in the laptop line in the order that they arrive (based on the chronological order of the input file). This outside line MUST be implemented using a linked-list based queue. Laptop Waiting Line: As mentioned, as soon as a student enters Lab 3A, they must stand in line to check out a laptop. You will implement this line as a queue. This Laptop Waiting Line MUST be implemented using a linked-list based queue. Stacks of Laptops: The laptops are to be stored in a stack and are identified by their unique serial number. Therefore, you will implement this as a stack. The input file will have a list of serial numbers (for the laptops) at the beginning of the input file. This serial numbers (laptops) will be placed (pushed) into the stack. This is constant over the whole simulation – i.e.: no new laptops are added after the beginning. However, the order in which they are stored in the stack will certainly change. Why? Students will check out the laptops and return them when finished; the result is the laptops will have new (different) positions inside the stack. Note: the laptop stack will NOT reset to its original state after each simulated day. Rather, the order of the laptops, at the end of any given day, will be the order for the start of the next day. You must implement this stack using arrays. (This is actually very easy!) Laptop Return Line: The laptop return line will also be implemented as a queue. This Laptop Waiting Line MUST be implemented using a linked-list based queue. Completed Registrations: Once a registration is finished, it MUST be saved into an ordered linked-list, which will be ordered alphabetically (by last name and then by first name). Although students may have the same last name or the same first name, it is guaranteed that all students have a unique first and last name combination. All registrations in this linked list must be erased on a daily basis at the time of printing the daily summary. Important Details: ? When a student arrives at Lab 3A, that student immediately enters the Laptop Check-out Line (during the same minute). ? Once at the front of the Laptop Check-out Line, you can only leave this line once a laptop is available. So even if you are at the front of the line, if no laptops are available, you will not leave the line. Let’s say a laptop becomes available at 12:20 PM, then, also at 12:20 PM, you will leave the laptop line and work with the Laptop Check-out Mudeer to check out a laptop, which then takes one minute, as described below, resulting in your getting the laptop at 12:21 PM. ? The “brief interaction” with the Laptop Check-out Mudeer takes one minute; meaning, it takes one minute to get a laptop. So if you arrive at 4:30 PM and find an empty laptop line, and even if laptops are available, you will not actually get your laptop until 4:31 PM. ? As such, a maximum of one laptop is dispensed every minute. So even if three students arrive at 1:12 PM, they will all enter the laptop line at 1:12 PM, and if all five laptops are available, the first student will get a laptop at 1:13 PM, the second at 1:14 PM, and the third at 1:15 PM. ? If a student gets a laptop at 4:31 PM, they will “finish” registering and will enter the Laptop Return Line at 4:36 PM. ? The “brief interaction” with the Laptop Return Mudeer also takes one minute; meaning, it takes one minute to confirm successful registration and return the laptop. So if you are at the front of the laptop return line at 4:40 PM, you will return the laptop and leave the Registration Lab at 4:41 PM. ? At a given minute, you could end up with a student taking a laptop from the stack and a student, who is finished, placing a laptop on the stack. So we need a rule: always process the student returning the laptop before processing the student taking a laptop. ? Students can arrive at the Registration Lab up until 4:59 PM. You are guaranteed that no student arrive after this time. ? The Registration Lab will officially closes at 5:00 PM. This means that no new students can enter the Lab at 5PM (or after). However, the office does stay open to finish the registrations of all students who arrived by 4:59 PM. So even if 100 students arrive right at 4:59 PM, this is no problem. The Registration Lab will stay open until all students have been processed. However, it is guaranteed that this will never take beyond 11:59 PM. Input File Specifications You will read in input from a file, "FCITregistrationLab.in". Have this AUTOMATED. Do not ask the user to enter “FCITregistrationLab.in”. You should read in this automatically. The file will contain an integer j followed by j random, unique laptop serial numbers. Next will be an integer n, followed by n number of days. For each day there will be an integer k, followed by k number of students, where each student’s information will be on a single line as follows: ENTERTIME LASTNAME FIRSTNAME ID NUMCLASSES ENTERTIME is the time in minutes from 12:00 PM. LASTNAME is the last name of the student arriving. FIRSTNAME is the first name of the student arriving. ID is the student's ID number. NUMCLASSES is the number of classes the student will register. Each student line is followed by NUMCLASSES lines with class data on each line: CLASSID DAYS TIME CLASSID is a string representing the ID of a class (ex. "CPCS-204"). DAYS is a string of letters representing the days of the week a class occurs on (ex. "S-T-R"). TIME is a string representing the time a class occurs at (ex. "10:30 AM - 12:00 PM"). Note: this time (10:30 AM - 12:00 PM) will need be stored as one string. Output File Specifications Your program must output to a file, called "FCITregistrationLab.out". You must follow the program specifications exactly. You will lose points for formatting errors and spelling. For each day, print out a header with the following format: ********** Day X: ********** Where X is the nth day of the simulation. Follow this header with one blank line. The following lines will give information about students entering, checking-out up a laptop, finishing registration and entering the laptop return line, making mistakes and having to redo the registration, and finally, returning the laptop upon successful completion of registration. These lines should be printed in the order in which the actions occur. The formatting for these lines is as follows: TIME: STUDENT_NAME has arrived at the Registration Lab and entered the Laptop Check-out Line. TIME: STUDENT_NAME has checked-out laptop # SERIAL. TIME: STUDENT_NAME finished registering and entered the Laptop Return Line. TIME: STUDENT_NAME successfully registered and returned laptop # SERIAL. Where TIME is the time an action occurred, STUDENT_NAME is the name of the student (first name, followed by a space, and then followed by the last name), and SERIAL is the serial number of the laptop the student is using. The time should be printed out in the following format: (H)H:MM PM The first one (or possibly two) digits represent the hour. The hour must not be printed as 0 if it is between noon and 1:00, so you’ll need to check for this. This is followed by a colon and then the next two digits represent the minute. If the minute value is less than 10, you’ll need to add a leading 0, so that it prints as 3:05, not 3:5. (It probably makes sense to have a method that takes in as input the number of minutes after 12:00 PM and, in turn, prints out the corresponding time in this format.) Follow each day's output with one blank line. Then you will print the day's statistics as follows: *** Day X: FCIT Daily Registration Report ***: The Registration Lab received Y registrations as follows: Where X is the day number (of the simulation), and Y is total number of students that came that day. This is followed by an alphabetical (last name, and then first) printout of all registrations that occurred during the given day: LASTNAME, FIRSTNAME, ID # STUDENTID Time Registered: (H)H:MM PM Classes: | CLASSID | DAYS | TIME | ... LASTNAME, FIRSTNAME, ID # STUDENTID Time Registered: (H)H:MM PM Classes: | CLASSID | DAYS | TIME | ... Where LASTNAME, FIRSTNAME, and STUDENTID are the respective student data. This is followed by the time that the student completed Registration (by returning the laptop to the Laptop Return Mudeer) and left the Registration Lab. Finally, this will be followed by the class data (CLASSID, DAYS, and TIME) of the classes the student registered for, printed in the order they were originally read in from the file. The print literal used to print the formatted list of registered classes is: "\t| %-8s | %-5s | %-19s |%n" Follow each day's summary with TWO blank lines. See sample input and output files for examples. ***Helpful Suggestions*** ? Read and FULLY understand this write-up BEFORE trying to code. ? As this is a simulation, the “work” will be done in the main loop that simulates over each minute of the day. During any given minute, many things get processed. You must process the Laptop Return Line, the “outside line”, the Laptop Check-out Line, the Laptop Checkout Mudeer, the Laptop Return Mudeer, and you must process the actual students who have laptops and are in the middle of registration (their 5 minutes). ? The order that you process these various elements will decide/dictate the order of the various print statements (shown above) that you will print to your output file. So you will need to study the sample output file provided to try to figure out what order you need to process (code) things in. ***WARNING*** Your program MUST adhere to this EXACT format (spacing capitalization, use of colons, periods, punctuation, etc). The graders will use very large input files, resulting in very large output files. As such, the graders will use text comparison programs to compare your output to the correct output. If, for example, you have two spaces between in the output when there should be only one space, this will show up as an error even through you may have the program correct. You WILL get points off if this is the case, which is why this is being explained in detail. Minimum deduction will be 10% of the grade, as the graders will be forced to go to text editing of your program in order to give you an accurate grade. Grading Details Your program will be graded upon the following criteria: 1) Adhering to the implementation specifications listed on this write-up. 2) Your algorithmic design. 3) Correctness. 4) Use of stacks and queues. If your program does not use stacks and queues, you will NOT get credit for the assignment. Period. 5) The frequency and utility of the comments in the code, as well as the use of white space for easy readability. (We're not kidding here. If your code is poorly commented and spaced and works perfectly, you could earn as low as 85-90% on it.) 6) Compatibility to the newest version of NetBeans and Java. (If your program does not compile in NetBeans, you will get a sizable deduction from your grade.) 7) Your output MUST follow to the EXACT output format shown in the sample output file. 8) Your program should include a header comment with the following information: your name, course number, section number, assignment title, date, AND EMAIL ADDRESS. 9) You should include comments throughout your code, when appropriate. Deliverables You should submit a zip file with SIX files inside: 1. FCITcourse.java Class to create object of type course…see UML below 2. FCITstudent.java Class to create objects of type FCIT student. These objects will be nodes of the queue and linked list. 3. FCITqueue.java Class to create queue of FCITstudent objects 4. FCITlaptopStack.java Class to create Stack for laptops 5. FCITregistrations.java Class to create linked list to hold registrations for a given day 6. FCITregistrationLab.java This is your main program. NOTE: your name, ID, section and EMAIL should be included as comments in all files! Hint: All three queues and the linked list store objects of type FCITstudent. Therefore, you only need to create one Class for a queue; then you will create three objects of this class (for the three queues). Here are the UML Diagrams for the required classes: FCITstudent Data Members private String firstName; private String lastName; private int ID; private int laptopSerialNumber; private int numberCourses; private FCITcourse[] courses; private int enterTime; private int timeRemaining; private int timeRegistered; private FCITstudent next; Operations/Methods CONSTRUCTOR (one or more constructors as needed) public String getFirstName( ) public String getLastName( ) public int getID( ) public int getLaptopSerialNumber( ) public int getNumberCourses( ) public FCITcourse[] getCourses( ) public int getEnterTime( ) public int getTimeRemaining( ) public int getTimeRegistered( ) public FCITstudent getNext( ) public void setFirstName( String ) public void setLastName( String ) public void setID( int ) public void setLaptopSerialNumber( int ) public void setNumberCourses( int ) public void setCourses( FCITcourse[] ) public void setEnterTime( int ) public void setTimeRemaining( int ) public void setTimeRegistered( int ) public void setNext( FCITstudent ) DETAILS: ? firstName and lastName should be obvious ? ID is the Student ID number ? laptopSerialNumber is the serial number of the laptop that the student used for registration ? numberCourses is the number of courses that the student wants to register for ? courses is an array of FCITcourse objects, where each object represents one of the specific courses the student wants to register for ? enterTime is the time that the student arrives at Lab 3A for registration. This time will be given as an integer, n, which represents the number of minutes after 12PM. So if n is 87, this means that the student arrived 87 minutes after 12PM, which is 1:27PM. ? timeRemaining is a countdown timer to measure the 5 minutes for registration ? timeRegistered is the time (in minutes) that the student returns the laptop and leaves the Lap ? next is the pointer to the next node FCITqueue Data Members private FCITstudent front; private FCITstudent back; Operations/Methods CONSTRUCTOR (one or more constructors as needed) public boolean isEmpty( ) public void enqueue( FCITstudent ) private FCITstudent enqueue( parameters here ) public FCITstudent dequeue( ) private FCITstudent dequeue( FCITstudent ) public FCITstudent peek( ) private FCITstudent peek( parameters here ) DETAILS: ? All variables and methods should be clear ? The come directly from the sample code FCITregistrations Data Members private FCITstudent head Operations/Methods CONSTRUCTOR (one or more constructors as needed) public boolean isEmpty( ) public void insert( FCITstudent head )) private FCITstudent insert( parameters here ) public void PrintRegistrations( ) public void PrintRegistrations( FCITstudent head ) DETAILS: ? This class is for the linked list ? All variables and methods should be clear ? The come directly from the sample code ? Note: we do not need (or use) all the linked list methods (such as delete), because we do not need them for our program. FCITcourse Data Members private String courseNumber; private String courseDays; private String courseTime; Operations/Methods CONSTRUCTOR (one or more constructors as needed) public String getCourseNumber( ) public String getCourseDays( ) public String getCourseTime ( ) public void setCourseNumber( String courseNumber ) public void setCourseDays( String courseDays ) public void setCourseTime ( String courseTime) DETAILS: ? courseNumber is the Number of the course Example: CPCS-204 ? courseDays is the days for the course Example: S-T-R (for Sun., Tues., Thurs.) Example: -M-W- (for Mon. & Wed. course) ? courseTime is the time of the course Example: 11:00 AM - 12:20 PM FCITlaptopStack Data Members private int[] stack; private int maxSize; private int top; Operations/Methods CONSTRUCTOR (one or more constructors as needed) public boolean isFull ( ) public boolean isEmpty ( ) public int pop( ) public int peek( ) public void push( int LaptopSerialNumber ) DETAILS: ? All variables and methods should be clear ? The come directly from the sample code