Project Description You will build part of a college\'s course registration syst
ID: 3691684 • Letter: P
Question
Project Description
You will build part of a college's course registration system to view and search the course catalog, and to add (register for) and drop (withdraw from) courses.
The following restrictions apply:
All courses meet only once per week, for one class period.
Days will be denoted by the following letters:
M - Monday, T - Tuesday, W - Wednesday, H - Thursday, F - Friday, S - Saturday. There are no Sunday courses.
Class periods (time slots) are numbered from 1 to 9.
A student cannot register for a course that is not in the catalog.
There is a limit on the number of courses a student may take in one semester.
There is NO explicit limit on the number of credits a student may carry in one semester.
A student cannot register for two courses that meet on the same day and time.
Objects Implementation (Phase 2)
Course.java contains the definition of a class called Course. A Course object represents an entry for a course in the catalog. Each Course object keeps track of the name of a course, its course number (department and individual course number), the day of week and class period at which the course is scheduled, and the number of credits earned for completing the course. The Course object also keeps track of the roster – a list of students currently enrolled in the course.
*****Implement Course.java.*****
Make sure all of your fields are private and your method signatures are written exactly as defined below.
*You can assume that all parameters being passed into the constructors will be in their valid ranges.*
*You can also assume that the objects passed into the ‘equals’ or ‘compareTo’ methods will NOT be null.”
Course.java :
public Course(int department, int courseNum, String name, char day, int timeSlot, int credits)
department and course numbers can range from 0 to 999
the day and time slot are used to create a Period object – do not store the day and time slot individually
credits range from 1-4
each course maintains a list (array) of students – maximum number of students for a course is 20
getter methods for all of the variables passed into the constructor:
public int getDepartment() //returns the department number
public int getCourseNumber() //returns the course number
public String getName() //returns the name of the course
public Period getPeriod() //returns the period of the course
public int getCredits() //returns the number of credits for the course
public Student[] getRoster() //returns the roster – list of students who are enrolled in the course
public String toString()return the course in the same format as in catalog.txt: “department:courseNum [name] period credits:credits”
ex: 198:111 [Introduction to Computer Science] T5 credits:4
public boolean equals(Course other)
two courses are considered equal if their department and course numbers are the same
-----
Period.java contains the definition of a class called Period. A Period object simply defines what day and time slot a class meets. For example, if a class meets on Mondays in time slot 5 (M5), it would store the day as ‘M’ and the time slot as 5.
*****Implement and submit Period.java.*****
Make sure all of your fields are private and your method signatures are written exactly as defined below.
*You can assume that all parameters being passed into the constructors will be in their valid ranges.*
*You can also assume that the objects passed into the ‘equals’ or ‘compareTo’ methods will NOT be null.”
Period.java :
public Period(char day, int timeSlot)
days are all uppercase (look at the restrictions above for possible values)
time slot ranges from 1-9
getter methods for all of the variables passed into the constructor:
public char getDay() //returns the day of the week the course meets
public int getTimeSlot() //returns the time slot of the day the course meets
public String toString()return the period formatted as follows: “FirstLetterOfDay_TimeSlot” (no underscore)
ex: Tuesday, time slot 5 would return “T5”
public int compareTo(Period other)
compares the current period to another period
return values:
0 if two periods are equal
-1 if the current period comes before the other period in the week/day
1 if the current period comes after the other period in the week/day
-----
Student.java contains the definition of a class called Student. A Student object represents an entry for a student in a class. Each Student object keeps track of the student’s first name, last name, student id, and graduation year. The Student object also keeps track of the student’s schedule – a list of classes the student is currently enrolled in.
*****Implement Student.java.*****
Make sure all of your fields are private and your method signatures are written exactly as defined below.
*You can assume that all parameters being passed into the constructors will be in their valid ranges.*
*You can also assume that the objects passed into the ‘equals’ or ‘compareTo’ methods will NOT be null.”
Student.java :
public Student(String firstName, String lastName, int id, int gradYear)
id must be 9 digits (valid range: 100000000-999999999)
graduation year ranges from 1900-2050
each student maintains a list (array) of courses – maximum number of courses for a student is 6
getter methods for all of the variables passed into the constructor:
public String getFirstName() //returns the student’s first name
public String getLastName() //returns the student’s last name
public int getId() //returns the student’s ID
public int getGradYear() //returns the student’s graduation year
public Course[] getSchedule() //returns the student’s schedule – list of courses a student is taking
public String toString()return the student in the following format: “id: lastName, firstName - gradYear”
ex: 123456789: Smith, Joe - 2020
public boolean equals(Student other)
two students are considered equal if their IDs are the same
Explanation / Answer
Course.java
public class Course {
private int department;
private int courseNum;
private String name;
private char day;
private int timeSlot;
private int credits;
private Student roster[] = new Student [20]; //array language
public Course(int department, int courseNum, String name, char day, int timeSlot, int credits) {
this.department = department;
this.courseNum = courseNum;
this.name = name;
this.day = day;
this.timeSlot = timeSlot;
this.credits = credits;
}
public int getDepartment() {
return department;
}
public int getCourseNum() {
return courseNum;
}
public String getName() {
return name;
}
public int getPeriod() {
return timeSlot; //this is supposed to return the period
}
public int getCredits() {
return credits;
}
public Student[] getRoster(){
return roster;
}
}
Period.java
public class Period{
private int timeSlot;
private char day;
public Period(char day, int timeSlot){
this.day= day;
this.timeSlot= timeSlot;
}
public char GetDay(){
return day;
}
public int GetTimeSlot(){
return timeSlot;
}
public String toString(){
return ""+this.day+this.timeSlot;
}
}
Student.java
public class Student{
private String firstName;
private String lastName;
private int id;
private int gradYear;
private Course schedule[]= new Course [6];
public Student (String firstName, String lastName, int id, int gradYear){
this.firstName=firstName;
this.lastName=lastName;
this.id=id;
this.gradYear=gradYear;
}
//need to track number of courses each student is registered in
public String getFirstName(){
return firstName;
}
public String getLastName(){
return lastName;
}
public int getId(){
return id;
}
public int getGradYear(){
return gradYear;
}
public Course[] getSchedule(){
return schedule; //review array syntax
}
public String toString(){
return id+":"+lastName+","+firstName+"-"+gradYear;//not sure if return will work like this
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.