In this assignment you will implement a very simple registrar
system that consists of a list of currently offered courses and a list
of currently registered students. In this context you will deal with
circularly referential data, learn to throw exceptions, verify the
integrity of data, implement the ISame
interface, use the
test harness, and design methods for moderately complex class hierarchy.
We provide for you a skeleton of the project: a number of partially defined classes that you will use. The first part is quite straighforward and each of you should work it out on your own, including the program you design in your etudes. You shoud then work in pairs on the second part, using either partner's solution to the first part as your base.
The registrar system should let you enroll a student in a course, drop the student from a course, cancel a course, and add a new course. It should also allow you to print student's schedule, and print the course roster.
Of course, only students enrolled at the university can register for courses, and they can only register for courses that are in the registrar system.
Student
class so that a
student can add a course to her/his schedule. Finish the design of the
Course
class, so that a student can be added to the
roster. Make sure that when student is added to the roster, the
added course appear immediately on his/her schedule.ISame
objects so that they, too implement the ISame
interface.Registrar
that represents the
registrar system. It contains a list of currently enrolled students
and a list of currently offered courses. Any new instance of the
Registrar
class will have no students and no
classes. The enrollStudent
and
withdrawStudent
must be used to make any changes in the list of students, and the
methods addCourse
, and cancelCourse
must
be used to make any changes to the current course offerings.
Design the method enrollStudent
in the
Registrar
class that enrolls the given student in the university.
Design the method withdrawStudent
in the
Registrar
class that withdraws the given student from the university.
Design the method addCourse
in the
Registrar
class that adds the given course to the current course offering.
Design the method cancelCourse
in the
Registrar
class that cancels the offering of the given course.
Add the same
method to the
Registrar
class, so that it implements the
ISame
interface.
Design the following methods that allow you to see the schedules, rosters, and lists of students and schedules:
toString
method for the class Student that prints
only the student's name and id.toString
method for the class Course that prints
only the course title an number.toString
method for the class AList that prints
every item in the list invoking its toString
method.toStringSchedule
method for the class Student
that prints only student's schedule (the course titles and
numbers only).toStringRoster
method for the class Course
that prints only the course roster (only the names and id-s of the
students).Design the method add
in the Registrar
class that enrolls a given student in the given course.
Your method must throw a NoSuchElementException
when
the registrar system does not contain the desired course, or when
the student who wishes to enroll in the course is not already
registered at the university.
Additionally, a student cannot be enrolled twice in the same
course. Signal this problem by throwing an
IllegalStateException
Using the students and courses from your previous examples, create a registrar system with at least three courses that have at least three students enrolled.
Include with your project a Comments.java file that consists entirely of a text describing how you handled the design of this method.
Hint: Many of these methods mutate your data. For
every test you will need a fresh copy of the data that will then
be modified by your method invocation. Your tests will check the
value of the objects after the mutation. We suggest that you
include an Examples
class that defines all objects
you will need in your tests. You can then reuse the same examples
repeatedly, without copying code:
class Examples{ // examples sof data we will use in all tests MyClass sampleData1 = new MyClass(...); MyClass sampleData2 = new MyClass(...); } class Tests{ one instance of the Examples class that will be reused Examples e = new Examples(); boolean testSomething(){ // make new instances of all sample data, in case they have been changed e = new Examples(); // change the values by invoking methods with effects e.sampleData1.mutate(...); e.sampleData2.mutate(...); ... // test the values of the sample data after the methods with effects sth.test("one test", e.sampleData1, expected-value); sth.test("two test", e.sampleData2, expected-value); ... } boolean testAnother(){ // make new instances of all sample data, in case they have been changed e = new Examples(); // change the values by invoking methods with effects e.sampleData1.mutate2(...); e.sampleData2.mutate2(...); ... // test the values of the sample data after the methods with effects sth.test("one test", e.sampleData1, expected-value); sth.test("two test", e.sampleData2, expected-value); ... } ... include the following in your code... sth.fullReport(); }
Add the limit on course enrollments to the class
Course
and make the necessary changes to make sure a
student cannot enroll in a course that is full.
Do not allow a student to register for more than four courses. (We could add a limit on the number of credits a student can take and add the number of credits to each course, but the limit on the number of courses we propose simplifies the program to make it reasonable.)