Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Objects Implementation (Phase 2) Course.java contains the definition of a class

ID: 3689914 • Letter: O

Question

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

Explanation / Answer

class Course{ int department; int courseNum; String name; char day; int timeSlot; int credits; Student students[] = 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.day = day; this.timeSlot = timeSlot; this.credits = credits; } public int getDepartment() { return department; } public int getCourseNumber() { return courseNum; } public String getName() { return name; } public Period getPeriod() { return null; } public int getCredits() { return credits; } public Student[] getRoster() { return students; } public String toString(){ return department+":"+courseNum +"["+name+"]"+ period +" "+ credits+":"+credits; } public boolean equals(Course other){ return courseNum==other.courseNum && department==other.department; } }