Project Description You will build part of a college\'s course registration syst
ID: 3694835 • 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. System Implementation (Phase 3) The user interface has been written for you in WebRegApp.java. This program handles all keyboard and file input, and all screen output. You will complete the following methods in WebReg.java, which are designed to perform actions such as searching and sorting the catalog. WebRegApp.java first reads the catalog (a list of courses) from catalog.txt. The catalog will be represented as an array of Course objects. WebRegApp reads the catalog from the file catalog.txt - you may edit this file if you wish. If you add entries to it, be sure they follow the same format as the entries already in the file. It then shows the user a menu from which they can choose various options. In most cases, WebRegApp will call methods from WebReg to execute the option chosen by the user. *ignore options 3 & 4 – you do not need to implement those methods until the next milestone. Courses for which the student registers should be placed into the student’s schedule array starting at index 0. Empty (unused) entries in the array should remain null; all empty entries should be on the right side of the array (there should be no "gaps" between used entries). For example, since the maximum number of courses allowed is 6 and if the student is currently taking 3 courses, the schedule array would be of size 6, entries 0 through 2 would contain Course objects, and entries 3 through 5 would contain null. This should be the case regardless of the sequence of adds and drops the student performed in order to create his or her current schedule. The same concept applies for the roster of students for a specific course. Implement the following methods in WebReg.java. DO NOT modify WebRegApp.java or your Period, Course, and Student objects. If needed, you may add helper methods and fields in WebReg.java. public static Course lookupCourseByName(Course[] catalog, String courseName) search for the course with the given name in the catalog, and return the corresponding Course object. if the course is not found, return null. *you may ignore the letter casing of the course name – in other words, if courseName is all uppercase but the name of the course in the catalog is all lowercase, it would still be a match. public static Course[] lookupCoursesByDept(Course[] catalog, int department) search for all courses offered by the given department in the catalog, and return the corresponding Course objects in a new array (in any order). the returned array should be just large enough to hold the results, and no larger; it should not contain any empty (null) entries. if no courses are found with that department number, return null. public static int countCredits(Student s) compute the student's current total credit load. public static boolean addCourse(Student s, Course c) attempt to add a course, c, to the student's schedule. put the Course object into the student’s schedule in the first free slot (null entry), update the courses’ roster, and return true. if the student is not allowed to register for this course (for any reason), return false and do not alter the student’s schedule or the courses’ roster. public static boolean dropCourse(Student s, Course c) attempt to remove a course, c, from the student's schedule. search for the Course object in the student's schedule. if you find the Course object in the student’s schedule, remove it from the student’s schedule, update the courses’ roster, making sure not to create any "gaps" (null entries between used entries), and return true. if you cannot find the course in the student's schedule or the student is not in the courses’ roster, return false. Remember to test each of your methods thoroughly by running WebRegApp! *WebRegApp acts as a single student – you should create your own test classes to test the course registration system with multiple students.* Submit WebReg.java.
public class Course{
private int department;
private int courseNum;
private String name;
private Period period;
private int credits;
private Student[] students;
public Course(int department, int courseNum, String name, char day, int timeSlot, int credits){
this.students = new Student[20];
this.department = department;
this.courseNum = courseNum;
this.name = name;
this.period = new Period(day,timeSlot);
this.credits = credits;
}
public int getDepartment(){
return department;
}
public int getCourseNumber(){
return courseNum;
}
public String getName(){
return name;
}
public Period getPeriod(){
return period;
}
public int getCredits(){
return credits;
}
public Student[] getRoster(){
return students;
}
public String toString(){
String a = "" + department+":"+courseNum+" ["+name+"] "+period.toString()+" credits:"+credits;
return a;
}
public boolean equals(Course other){
if(this.department == other.getDepartment() && this.courseNum == other.getCourseNumber()){
return true;
} else{
return false;
}
}
}
public class Period {
private char day;
private int timeSlot;
public Period(char day, int timeSlot){
if(day >= 'a' && day <= 'z'){
day = (char) (day + (int)'A' - (int)'a'); // converting to uppercase here
}
this.day = day;
this.timeSlot = timeSlot;
}
public char getDay() {
return day;
}
public void setDay(char day) {
this.day = day;
}
public int getTimeSlot() {
return timeSlot;
}
public void setTimeSlot(int timeSlot) {
this.timeSlot = timeSlot;
}
public String toString() {
return "" + day + "" + timeSlot;
}
public boolean equals(Period p){
return day == p.day && timeSlot == p.timeSlot;
}
public int compareTo(Period other){
if(equals(other)){
return 0;
}
else{
if(other.day == day){
if(timeSlot < other.timeSlot){
return -1;
}
else{
return 1;
}
}
else{
String days = "SMTWF";
int ind1 = days.indexOf(day);
int ind2 = days.indexOf(other.day);
if(ind1 < ind2){
return -1;
}
else{
return 1;
}
}
}
}
}
public class Student {
private String firstName;
private String lastName;
private int id;
private int gradYear;
Course courses[] = 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 firstName;
}
public String getLastName() {
return lastName;
}
public int getId() {
return id;
}
public int getGradYear() {
return gradYear;
}
public Course[] getSchedule() {
return courses;
}
public void setSchedule(Course[] courses) {
this.courses = courses;
}
public String toString() {
return id+": "+lastName+", "+firstName+" - "+gradYear;
}
public boolean equals(Student other) {
if(this.id == other.id){
return true;
}
else{
return false;
}
}
}
Explanation / Answer
Hello there ,
Please find below class which contains 5 methods.
Do I need to implement menu item 3/4 ? As You have not asked for.
Let me know if you have any queries . Thanks.
public class WebReg {
public static Course lookupCourseByName(Course[] catalog, String courseName) {
Course course = null;
// iterate the String array
for (int i = 0; i < catalog.length; i++) {
// check if course array contains the string
if (catalog[i].getName().toLowerCase().equals(courseName.toLowerCase())) {
// course found
course = catalog[i];
break;
}
}
return course;
}
public static Course[] lookupCoursesByDept(Course[] catalog, int dept) {
Course[] courses1 = new Course[catalog.length];
int index = 0;
// iterate the String array
for (int i = 0; i < catalog.length; i++) {
// check if course array contains the dept
if (catalog[i].getDepartment() == dept) {
// course found
courses1[index] = catalog[i];
index++;
}
}
Course[] courses = new Course[index];
System.arraycopy(courses1, 0, courses, 0, index);
return courses;
}
public static int countCredits(Student me) {
Course[] courses = me.getSchedule();
int countOfCredits = 0;
for (int i = 0; i < courses.length; i++) {
countOfCredits = countOfCredits + courses[i].getCredits();
}
return countOfCredits;
}
public static boolean addCourse(Student me, Course c) {
Course[] coursesRegistered = me.getSchedule();
if (!contains(coursesRegistered, c)) {
for (int i = 0; i < coursesRegistered.length; i++) {
if (coursesRegistered[i] == null) {
coursesRegistered[i] = c;
return true;
}
}
} else {
return false;
}
return false;
}
public static boolean dropCourse(Student me, Course c) {
Course[] coursesRegistered = me.getSchedule();
Course[] coursesRegisteredUpdated = new Course[coursesRegistered.length - 1];
boolean changed = false;
if (contains(coursesRegistered, c)) {
int index = 0;
for (int i = 0; i < coursesRegistered.length; i++) {
if (coursesRegistered[i] == c) {
changed = true;
continue;
} else {
coursesRegisteredUpdated[index] = coursesRegistered[i];
index++;
}
}
me.setSchedule(coursesRegisteredUpdated);
} else {
return false;
}
return changed;
}
public static boolean contains(Course[] coursesRegistered, Course c) {
if (coursesRegistered[0] != null) {
for (Course course : coursesRegistered) {
if (course.getName().equals(c.getName()))
return true;
}
} else {
return false;
}
return false;
}
}
=====O/P=====
Menu:
1. Look up course by name
2. Look up courses by department
3. View catalog, sorted by department/course number
4. View catalog, sorted by scheduled day/period
5. View my course schedule
6. View my current credit load
7. Register for a course
8. Withdraw from a course
9. View a courses' roster
10. Quit
Choice (1-10)?
7
Enter course name:
Playwriting
Successfully registered.
Menu:
1. Look up course by name
2. Look up courses by department
3. View catalog, sorted by department/course number
4. View catalog, sorted by scheduled day/period
5. View my course schedule
6. View my current credit load
7. Register for a course
8. Withdraw from a course
9. View a courses' roster
10. Quit
Choice (1-10)?
5
Current schedule:
965:315 [Playwriting] W4 credits:3
null entry in array
null entry in array
null entry in array
null entry in array
null entry in array
Menu:
1. Look up course by name
2. Look up courses by department
3. View catalog, sorted by department/course number
4. View catalog, sorted by scheduled day/period
5. View my course schedule
6. View my current credit load
7. Register for a course
8. Withdraw from a course
9. View a courses' roster
10. Quit
Choice (1-10)?
7
Enter course name:
Principles of Astrophysics
Successfully registered.
Menu:
1. Look up course by name
2. Look up courses by department
3. View catalog, sorted by department/course number
4. View catalog, sorted by scheduled day/period
5. View my course schedule
6. View my current credit load
7. Register for a course
8. Withdraw from a course
9. View a courses' roster
10. Quit
Choice (1-10)?
5
Current schedule:
965:315 [Playwriting] W4 credits:3
105:342 [Principles of Astrophysics] T5 credits:3
null entry in array
null entry in array
null entry in array
null entry in array
Menu:
1. Look up course by name
2. Look up courses by department
3. View catalog, sorted by department/course number
4. View catalog, sorted by scheduled day/period
5. View my course schedule
6. View my current credit load
7. Register for a course
8. Withdraw from a course
9. View a courses' roster
10. Quit
Choice (1-10)?
8
Enter course name:
Principles of Astrophysics
Successfully withdrawn.
Menu:
1. Look up course by name
2. Look up courses by department
3. View catalog, sorted by department/course number
4. View catalog, sorted by scheduled day/period
5. View my course schedule
6. View my current credit load
7. Register for a course
8. Withdraw from a course
9. View a courses' roster
10. Quit
Choice (1-10)?
5
Current schedule:
965:315 [Playwriting] W4 credits:3
null entry in array
null entry in array
null entry in array
null entry in array
Menu:
1. Look up course by name
2. Look up courses by department
3. View catalog, sorted by department/course number
4. View catalog, sorted by scheduled day/period
5. View my course schedule
6. View my current credit load
7. Register for a course
8. Withdraw from a course
9. View a courses' roster
10. Quit
Choice (1-10)?
2
Enter number of department:
105
105:343 [Observational Radio Astronomy] M2 credits:3
105:342 [Principles of Astrophysics] T5 credits:3
Menu:
1. Look up course by name
2. Look up courses by department
3. View catalog, sorted by department/course number
4. View catalog, sorted by scheduled day/period
5. View my course schedule
6. View my current credit load
7. Register for a course
8. Withdraw from a course
9. View a courses' roster
10. Quit
Choice (1-10)?
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.