Project Description You will build part of a college\'s course registration syst
ID: 3691055 • Letter: P
Question
Project Description You will build part of a college's course registration system (similar to WebReg, though considerably less complex). The system will keep track of a catalog of courses that students can take. It will allow the user (a student) 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) 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
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;
}
public String getFirstName()
{
return this.firstName;
}
public String getLastName()
{
return this.lastName;
}
public int getId()
{
return this.id;
}
public int getGradYear()
{
return this.gradYear;
}
public Course[] getSchedule()
{
return this.schedule;
}
public String toString()
{
return "" + this.id + ": " + this.lastName + ", " + this.firstName + " - " + this.gradYear;
}
public boolean equals(Student other)
{
if(this.id == other.id)
{
return true;
}
return false;
}
}
Period.java
public class Period
{
private char day;
private int timeSlot;
public Period(char day, int timeSlot)
{
this.day = day;
this.timeSlot = timeSlot;
}
public char getDay()
{
return this.day;
}
public int getTimeSlot()
{
return this.timeSlot;
}
public String toString()
{
return "" + this.day + this.timeSlot;
}
public int compareTo(Period other)
{
if(this.day == other.day && this.timeSlot == other.timeSlot)
{
return 0;
}
else if(dates(this.day) < dates(other.day))
{
return -1;
}
else if(dates(this.day) == dates(other.day))
{
if(this.timeSlot < other.timeSlot)
{
return -1;
}
else
{
return 1;
}
}
else
{
return 1;
}
}
public int dates(char day)
{
if(day == 'M')
{
return 0;
}
else if(day == 'T')
{
return 1;
}
else if(day == 'W')
{
return 2;
}
else if(day == 'H')
{
return 3;
}
else if(day == 'F')
{
return 4;
}
else if(day == 'S')
{
return 5;
}
return -1;
}
}
Course.java
public class Course
{
private int department;
private int courseNum;
private String name;
private Period period;
private int credits;
private Student[] roster = new Student[20];
public Course(int department, int courseNum, String name, char day, int timeSlot, int credits)
{
this.department = department;
this.courseNum = courseNum;
this.name = name;
this.period = new Period(day, timeSlot);
this.credits = credits;
}
public int getDepartment()
{
return this.department;
}
public int getCourseNumber()
{
return this.courseNum;
}
public String getName()
{
return this.name;
}
public Period getPeriod()
{
return this.period;
}
public int getCredits()
{
return this.credits;
}
public Student[] getRoster()
{
return this.roster;
}
public String toString()
{
return "" + this.department + ":" + this.courseNum + " [" + this.name + "] " + this.period + " credits:" + this.credits;
}
public boolean equals(Course other)
{
if(this.department == other.department && this.courseNum == other.courseNum)
{
return true;
}
return false;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.