Version: 5.2.1

Lab 6a: Circularly Referential Data

Goals: The goals of this lab is to learn how to design and use circularly referential data.

In this part we’ll visit a familiar concept where circular data exists – namely, lists of friends , or buddy lists. These buddy lists could be IM buddy lists, ICQ buddy lists, or lists of friends on social networks. Intuitively a buddy list is just a username and a list of other buddies; the latter part is where we get circularity.

Download the files in Lab6-Buddies.zip. The folder contains the files:

Person.java

ILoBuddy.java

MTLoBuddy.java

ConsLoBuddy.java

ExamplesBuddies.java

Create a project Lab6-Buddies and import the five files listed above into the default package. Add the tester.jar library to the project as you have done before.

All errors should have disappeared and you should be able to run the project.

If someone wants to invite a lot of friends to a party, he or she calls all people on his or her list of buddies, and asks them to invite their friends (buddies) as well, and ask their friends to invite any of their friends as well (anyone that can be reached through this network of friends.

We call those on the person’s buddy list the direct buddies and the others that will also be invited to the party the distant buddies.

Now we would like to ask some pretty common questions. For each question design the method that will find the answer. The purpose/effect statements and the headers for the methods are already given:

Homework Assignment

Design the method that provides the answer to the following question:

How many people will be at the party if all those a person invites (directly or indirectly) show up?

// returns the number of people who will show up at the party

// given by this person

int partyCount()

Follow the Design Recipe!