CS102 Spring 2012

Assignment 3

Extending club membership

In this assignment you will extend the work you started in Lab 4 on the club project to include a method that returns the number of members who joined our club in a given month, and a method to purge members who joined our club in a given month and year, returning a collection of those members purged.

Prep

  • Create an assign3 directory under your cs102 course directory. This is the directory in which you will create your BlueJ project.
  • The starter code for this assignment is where you left off at the end of Lab 4, but don’t modify your Lab 4. Instead, make a copy of it under your assign3 directory:
    $ cp -r ~/cs102/lab4/  ~/cs102/assign3/

Tasks

For this assignment you will implement and test the challenge exercises for this assignment, as described in the BlueJ project’s README.TXT file.

Challenge Exercise 1

Define a method in the Club class with the following signature and description:

    /** 
     * Return how many members joined in the given month. 
     * @param month The month we are interested in. 
     * @return How many members joined in the given month. 
     */
    public int joinedInMonth(int month)

If the month parameter is outside the valid range of 1-12, print an error message and return zero.

Challenge Exercise 2

Define a method in the Club class with the following signature and description:

    /**
     * Remove from the club's collection all members who joined
     * in the given month and year, and return them stored in a 
     * separate collection object.
     * @param month The month of the Membership.
     * @param year The year of the Membership.
     * @return A collection of members purged
     */
    public ArrayList<Membership> purge(int month, int year)

If the month parameter is outside the valid range of 1-12, print an error message and return a collection object with no objects stored in it.

Note: the purge method is significantly harder to write than any of the others.

Examples

Don’t forget to add tests in your Examples class that test the methods you implemented above.

Finishing Up

Once you have completed the above exercises, all the tests you added in your Examples class pass, and your name is in the header comments for all your *.java files:

  1. submit this assignment electronically, using the submit102 script
courses/cs102-201201/assigns/assign3.txt · Last modified: 2012/02/13 00:44 by mlsmith
VCCS Top Events Extended Site Search Login Vassar Science Web Vassar Home Driven by DokuWiki Valid XHTML 1.0