This assignment will have you working with arrays, classes, getters, setters, and enums.
Now that summer registration is finally over, you have been officially hired to create a new course registration system. The new system will be similar to the old system, but there are a few marked differences. For example, in your system there will be no restrictions on registration. However, most of the features such as adding classes, a maximum waitlist size, a class size, having no conflicting class times, and others will stay the same.
You will be given Course.java
, Department.java
, LectureDays.java
, LectureTime.java
, Student.java
, and Time.java
. Some of these files (Time.java
and LectureTime.java
) have already been completed and you don’t need to make any changes to them. The rest are either partially complete or need to be completed entirely by you.
This class has two instance variables:
private int hour
: the hour of the timeprivate int minute
: the minute of the timeAdditionally it has the following methods:
public Time(int hour, int minute)
: the constructor for the Time class.public int getHour()
: The getter method for hour
public int getMinute()
: The getter method for minute
public String toString()
: toString method for time, returns string in the format of 24-Hour Time (HH:MM)public boolean before(Time time)
: timeA.before(timeB) returns true if timeA occurs before or at the same time as timeB and false otherwise.
NOTE: This class is provided for you and should not be modified.
This class has three instance variables:
private LectureDays days
: Denotes the days of the class. Either LectureDays.MWF
or LectureDays.TTH
.private Time startTime
: Denotes the time at which the lecture startsprivate Time endTime
: Denotes the time at which the lecture ends.The class also contains the following methods:
public LectureTime(LectureDays days, int startHour, int startMinute, int endHour, int endMinute)
: The constructor for LectureTime.public LectureDays getDays()
: The getter method for days
public Time getStartTime()
: The getter method for startTime
public Time getEndTime()
: The getter method for endTime
public boolean overlap(LectureTime time)
: lectureTimeA.overlap(lectureTimeB) returns true if lectureTimeA and lectureTimeB overlap and false otherwise.
NOTE: This class is provided for you and should not be modified.
This is an enum with the following constants:
Additionally there should be a public String toString()
method that returns the abbreviation for the constant. The abbreviations (listed in the same order as the Department constants above) are:
This should be an enum with the following constants:
This class will be used to represent students. The constructor should take in only a String, denoting the students name. Additionally, each student needs the following instance data:
private Course[] courses
: an array of courses the the student is signed up to take. Should be initialized with size 5.private Course[] waitlists
: an array of courses that the student is waitlisted in. Should be initialized with size 5.private int numCoursesRegistered
: the number of courses that student is takingprivate int numCoursesWaitlisted
: the number of courses that the student is waitlisted inprivate int credits
: the number of credits the student is taking AND waitlisted forprivate String name
: the name of the student
Note: A student is taking a course if they are in the course i.e. registered for it and not waitlisted.
It is important to realize, in our system, that in our new registration system that if a student is taking four 3-credit classes and waitlisted in one 3 credit class, they are classified as taking 15 total credits.
Additionally the class should contain the following methods:
public String getName()
: A getter method for namepublic int getCredits()
: A getter method for creditspublic int getNumCoursesRegistered
: A getter method for numCoursesRegisteredpublic int getNumCoursesWaitlisted
: A getter method for numCoursesWaitlistedpublic Course[] getCourses()
: A getter method for coursespublic Course[] getWaitlists[]
: A getter method for waitlistspublic boolean availableAt(LectureTime time)
: Takes in a LectureTime and returns true
if the student does not have a class (both waitlisted and those he’s successfully taking) at the same time as LectureTime, and false
if they do.protected void register(Course course)
: Adds course
to courses
. Note that if courses
is full, then the size of courses
should be doubled and course
should then be added.protected boolean waitlist(Course course)
: Returns false if the student is waitlisted for five or more courses, and true otherwise. If the student is waitlisted for fewer than 5 courses, the method adds course
to waitlists
. (In our registration system, we do not allow a student to be waitlisted for more than five courses.)public boolean registeredForCourse(Course course)
: Returns true if the student is either taking or waitlisted for a a course and false otherwise.public String toString()
: toString method for the Student class. Should return the name of the student.public boolean signUp(Course course)
: Calls and returns course.addStudent(this)
. (If addStudent is implemented correctly, it should returns whether the student was successfully registered for the class). This method is provided for you, and should not be modified.protected boolean promotedFromWaitlist(Course course)
: Promotes the student from the waitlist after they get into the class. This method has been provided for you and should not be modified.Finally you will be creating the course class which will have the following instance data:
private static int numCoursesOffered
: A static variable counting the number of courses being offered by the universityprivate int courseNumber
: The course number of the courseprivate Department dept
: The department offering the classprivate int credits
: The number of credits that the course is worthprivate int classSize
: The maximum class size of the class; any students added after there are classSize students will be waitlistedprivate int waitlistCap
: The maximum length of the waitlist.private Student[] registeredStudents
: A list of students registered for the class. This includes both students signed up to take the class and waitlisted students. Note that the list should store the students in the order in which they were added. The array should be of size classSize + waitlistCap
and should not change size unless classSize
changes.private int numStudentsRegistered
: The number of students that are registered for the class (both taking and waitlisted)private LectureTime time
: The time that the course takes place;Additionally the class should have the following methods:
public Course(Department dept, int courseNumber, int credits, int classSize, int waitlistCap, LectureTime time)
: The constructor for the Course class.public static int getNumCoursesOffered()
: The getter method for numCoursesOffered
.public int getCredits()
: The getter method for credits
public Department getDept()
: The getter method for dept
public void setDept(Department department)
: The setter method for dept
public Student[] getRegisteredStudents()
: The getter method for registeredStudents
public int getNumStudentsRegistered()
: The getter method for numStudentsRegistered
public LectureTime getTime()
: The getter method for time
public int getClassSize()
: The getter method for classSizepublic boolean setClassSize(int size)
: Returns false
if size is less than or equal to classSize and true
otherwise. If false
, the operation failed and nothing should occur. If true
, set classSize
to size
. You will also have to resize the registeredStudents
array and use the promotedFromWaitlist(Course course)
method in the Students class as some students will be bumped up from the waitlist as the class size is expanded.public Student getRegisteredPosition(int i)
: returns the student at position i
in the registeredStudents list. Returns null
if there is no such student at the position or the position is bigger than the size of the array.protected boolean addStudent(Student student)
: If successful, the method adds the student to the registeredStudents array and returns true. The operation fails and returns false: if the registeredStudents array is filled, if the student will be taking more than 18 credits after registering, if the student is already registered for the class, if the student is not availiable during the course time, or if the student is to be placed on the waitlist but is already waitlisted in five or more classes.public String toString()
: Returns a string that is the Department abbreviation concatenated with the course number. Ex. if dept is COMPUTERSCIENCE and courseNumber is 1331, the method should return: “CS1331” (without quotes).You should not import any libraries or packages that trivialize the assignment. This includes data structures other than arrays (so no List
, Map
, Set
, etc). If you are unsure of whether something is allowed, ask on Piazza. In general, if something does a large part of the assignment for you, it is probably not allowed. Important: java.util.Arrays
is not allowed. However, that is different from a Java array (e.g int[] nums = new int[10]
), which is necessary for this assignment.
To compile your code, you need to go to the root directory (the folder hw2) and run javac registration/*.java utils/*.java
.
We have provided a tester file for hw2. To run the tests, move the Test.java into the hw2 directory. To compile, open you command prompt and ensure that you are in the root directoy (the hw2 folder). Then, use the command javac registration/.java utils/.java *.java to compile your code. To run you code simply use the java Test command. Also, note that passing these test cases will not guarantee that you will get an 100 or not lose any points on the assignment. While this file should help you debug your code, we highly encourage you to look through your own code and do some of your owns tests to ensure it’s bug free.
If you wish to test your code by creating a new java file put the test file in the root directory (hw2) and at the top of the test file (above the public class ...
) include the lines following lines:
import registration.Course;
import registration.Student;
import registration.Department;
import registration.LectureDays;
import registration.LectureTime;
import utils.Time;
Afterwards, to compile this testing file with everything else use javac registration/*.java utils/*.java *.java
. Afterwards run your test file by using java testfilename
as you normally would.
Starting from this homework, you will need to write Javadoc comments along with checkstyling your submission.
Every class should have a class level Javadoc that includes @author <GT Username>
and @version <version #>
.
Every method should have a Javadoc explaining what the method does and includes any of the following tags if applicable.
@param <parameter name> <brief description of parameter>
@returns <brief description of what is returned>
@throws <Exception> <brief explanation of when the given exception is thrown>
See the CS 1331 Style Guide section on Javadoc comments for examples.
You must run checkstyle on your submission. The checkstyle cap for this submission is 15 points. In future homeworks we will be increasing this cap, so get into the habit of fixing these style errors early!
A guide for setting up and running checkstyle can be found on this page on the course website. Make sure you click “Save” when downloading the jar file, and not “Run”. To run, copy the jar file into the registration folder. Run checkstyle for this assignment with java -jar checkstyle-6.2.2.jar -a *.java
. This will check for both checkstyle errors and javadoc errors.
When completing homeworks for CS1331 you may talk with other students about:
You may not discuss, show, or share by other means the specifics of your code, including screenshots, file sharing, or showing someone else the code on your computer, or use code shared by others.
Examples of approved/disapproved collaboration:
Collaborating with others in a way that violates the approved means is a Georgia Tech Honor Code violation, and you will also break your TAs hearts :broken_heart:
Export the hw2 folder and its contents to a .zip file and submit the .zip file on T-Square as an attachment. Make sure the zip file contains Course.java
, Department.java
, LectureDays.java
, LectureTime.java
, Student.java
, and Time.java
. When you’re ready, double-check that you have submitted and not just saved a draft.
Practice safe submission! Verify that your HW files were truly submitted correctly, the upload was successful, and that your program runs with no syntax or runtime errors. It is solely your responsibility to turn in your homework and practice this safe submission safeguard.
This procedure helps guard against a few things.