CS230

 

Lab: Linked Lists - Student Organizations

Solutions

Student.java

StudentClub.java

StudentOrganizations.java

Goals:

Gaining experience with:

  • Inheritance
  • Java's LinkedList API
  • Managing lists of Objects
  • BlueJ's debugger

Student Organizations at Wellesley College

[START PRELAB]

Task 0: BlueJ Debugger

Please watch this video Introducing the BlueJ Debugger

Student Organizations at Wellesley College are clubs, created and managed entirely by students, with the purpose of enhancing the Wellesley Community. Students are encouraged to participate in these clubs. They can also create new Student Organizations if they feel they are needed to cover some interest. There are currently over 200 student organizations at Wellesley College.

A Student Organization has a president, may have a vice-president, as well as regular members. All Organization members need to be current Wellesley students. Once a student has graduated, they cannot be a member any more.

For this lab, we will use Java's LinkedLists (click for LinkedList Java API) to represent the members in Student Organizations. Every node in such a List will contain an object of type ClubStudent. Linked Lists offer themselves as a suitable type of data structure in this application, since the number of members in a student organization is not known in advance, and also this number will grow and shrink over the organization's lifetime.

Task 1: ClubStudent.java

We are providing you with two classes, named Student and ClubStudent. Download the starting code.

First, notice that the Student class implements the Java Comparable Interface. Pay particular attention to the equals() and compareTo() method definitions. According to these definitions what does it mean for a Student instance to be greater (or smaller) than another one? What does it mean for two such instances to be equal?

Now, take a closer look at the ClubStudent class. What properties and methods does a ClubStudent instance inherit from its parent? What are the relevant characteristics of a ClubStudent, that have been added onto the Student data? What about relevant behaviors?

[END PRELAB]

Task 2: StudentOrganization.java, using Java's LinkedList

In this task is to define a new class, named StudentOrganization. We will use Java's LinkedList in this definition.

For the purposes of this application, we are interested in keeping track of the name, the members, the president and the vice-president of an organization.

Question: What is the relationship between the two classes: ClubStudent and StudentOrganization?

Start your StudentOrganization class implementation:

  1. Set up its instance variables

    • an instance variable of type LinkedList, named members, to hold objects of type ClubStudent
    • instance variables to hold the name of the Organization, its president and vice-president
  2. Write a 1-parameter constructor that takes the name of the Organization as its only input. It is used to just create an Organization without members, president or vice president.

    Test this constructor, even at this early point. You do not expect much to happen yet, but at least you should not see any "abnormal" behaviors.

  3. Write some instance methods

    • toString() that provides for a reasonable string representation of a Student Organization object. Make sure to test this method, even if it is on an empty organization!

    • numOfMembers() a method to return the size of the organization.

    • addMember() to add a member to the organization. Does it need an input argument? What type? How should this method behave if the object specified to be added to the organization is already there? Remember that since you are using Java's LinkedLists implementation, its API can have lots of useful methods already defined for you to use!

    • isMember() a method to report whether the input student is a member of the organization or not: if the input student belongs in the organization, the method returns the student itself, otherwise it returns null.

At this point you are in a position to do some comprehensive testing of all your code so far. Add a few members to your clubs and test that they are printed correctly.

Task 3: Traversing a List

Add a method to return all the members that have not paid their fees. What structure are you going to use to hold these members?

Task 4: The BlueJ Debugger

We will demonstrate the BlueJ debugger on our version of StudentOrganization program. Then, try your hands on using the debugger on your own program.