Comp 170 Lab 2 - Adding to the Club database         Feb 2, 2009

Goals

Overview

For this lab you are to take the "stub" Club project -- dealing with club membership records -- and add some features. The club project is zipped here; save it and open it. I've added a few things that are not in the version from the book. You are to extend the constructor in class Membership, and add the methods indicated below to class Club.

The Constructor

The existing constructor for Membership has parameters for name, month, and year. I've added a field donations to this class; create a second constructor with parameters for name, month, year, and donations. Do not delete or change the existing constructor.

Methods / Loops

You are to provide the following methods to class Club to do the indicated things. A stub method is provided for each.

1. join(Membership member): This will add member to the list members.

2. listMembers(): This will be a loop to print all the members. A good model is the Notebook listNotes() method.

3. search(String s): Prints all members whose name contain the given string s as a substring. To check if s is contained in a member, use the library contains() method as follows:
        if ( member.getName().contains(s)  ) {
            // print member
        }

If you use a for-each loop, member would be the for-each variable; if you use a while loop, you will need something like

        Membership member = members.get(N);    

4. totalDonations(): Returns (not prints) the sum of the donations of all the members. You will need a temporary variable such as sum.

5. Optional, for 1 point of extra credit: write earliestMember(): Prints the member who joined earliest. It is acceptable to print the member with the smallest year of joining, and to ignore ties. This is again done with a loop: you loop through all the elements of members, and keep a running record of minYear, the smallest year of joining seen so far, and also minMember, the member whose year of joining is minYear. (Alternatively, you can keep track of int position, the position in the list of the earliest member, so minMember is members.get(position).)

    int minYear = 3000;			// initialize to a value >= any valid year
int position = 0; // not used here
Membership minMember = null;
for (Membership m : members) {
if (m joined even earlier than minYear) { // earliest year found so far
minMember = ??;
minYear = ??;
}
}
After the completion of the loop, you print out minMember, the club member with the given position.

Email me your completed project. To create a zipfile out of a folder, navigate to the folder in the Windows Explorer (that is, not in BlueJ), right-click on the folder, and select Send To => Compressed (zipped) folder. This should create an ordinary file named <foldername>.zip. Then attach that zipfile to an email to me.