General: This class will contain information about a coursethat
is being offered at a university, and is designed for use incourse
enrollment systems and other similar systems. At this timewe will
not worry about sections of courses.
- id (private): a string that containsthe course mnemonic such as "CS201" or "ENGR162". Two Courseobjects that have the equal values (case-insensitive) for theirnames are considered equal to each other. This field is immutable,i.e. once a Course object is created with a given id value, thatfield's value cannot be changed.
- name (private): a string thatcontains the title of the course in any form, such as "SoftwareDevelopment Methods" or "Introduction to Basket Weaving". Likethe id, this field cannot be updated afterthe class object is created.
- roll (private): an ArrayList (or any other list-typeobject) that stores the set of students that are enrolled in thecourse. Each item in this list will be an object reference to aStudent object. This should be able to hold at least 5 items.
- Constructors: provide a constructor that takes a value forthe id and name fields.
- Accessors (AKA getters): provide public methods thatreturn references to the id, name and roll fields.
- Mutators (AKA setters): no mutators are required (since idand name are immutable).
- boolean add(Student aStudent): a public function that addsthe student object referenced by aStudent to the list of studentsstored in the course's roll object. The function returns false ifthe student is already enrolled in the course, or if the Studentcannot be added to the list for some other reason. Otherwise, itreturns true to indicate success. Also, this method adds the courseto the given student object's list of courses.
- boolean drop(Student aStudent): a public function whichremoves the student object referenced by aStudent from the list ofstudents stored in the course's roll object. The function returnsfalse if the student is not enrolled in the course, or if thestudent cannot be removed from the list for some other reason.Otherwise, it returns true to indicate success. Also, this methodremoves the course from the given student object's list ofcourses.
- void cancel(): a public function which drops all thestudents enrolled in the course. Also, for each student inthe roll list, it removes the course from that student's list ofcourses.
- public String toString(): write this method in the style:"ID: "+id+"; Name: "+name+"; Number of students:"+roll.size();
- public String rollAsString(): this method gives arepresentation of the list of students in the course as a string(perhaps for printing). Hint: This can be a one-liner -- justreturn roll.toString()!
- public booleanequals(Object s2): returns true if thetwo Course objects' id fields have the same value. (Hint: useequals() not == to test the two id values. )