CS U213 Spring 2007 - Assignment 7

Start the work on this project with the files given here. Include the given two jar files in your project.

Introduction

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.

Project Overview

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.

Etudes

  1. Finish the design of the 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.
  2. Make examples of students and courses -- you must have at least ten students and five courses. You can have more, but are not required to do so.
  3. Modify the classes that represent a list of ISame objects so that they, too implement the ISame interface.

Pair Programming Assignment

  1. Design the class 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.
  2. Design the method enrollStudent in the Registrar class that enrolls the given student in the university.

  3. Design the method withdrawStudent in the Registrar class that withdraws the given student from the university.

  4. Design the method addCourse in the Registrar class that adds the given course to the current course offering.

  5. Design the method cancelCourse in the Registrar class that cancels the offering of the given course.

  6. Add the same method to the Registrar class, so that it implements the ISame interface.

  7. Make several examples of the registrar system -- one with no courses, one with no students, and one with multiple students and courses.
  8. Design the following methods that allow you to see the schedules, rosters, and lists of students and schedules:

  9. 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.

  10. 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();
    
    }
    

    Extra Credit Assignment

    1. 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.

    2. 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.)


    Last modified: Wed Feb 28 08:39:15 EST 2007