On this page:
Problem 1: Buddy Lists
7.7

Lab 7: Working with Cyclic Data

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

You may work with your partner for this lab.

Problem 1: Buddy Lists

Related files:
  Buddies.zip  

In this lab, we’ll look at how circular data naturally appears in lists of friends, or ‘buddy lists.’ These buddy lists could be IM buddy lists, Twitter followers, or lists of friends on social networks. Intuitively, a buddy list is just a username and a list of other buddies. If two people are on each other’s buddy lists, we immediately get circularity.

Download the Buddies.zip file above. It contains the files:

(NOTE: We’re using non-generic lists in the lab deliberately, so we can add whatever helper methods we need. Really, these lists are being used as part of a graph, and so they might deserve to have some special-purpose methods.)

Create a project LabBuddies 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 (and ask them to invite their friends in turn...), eventually inviting 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 indirect buddies. (Note: some people technically qualify as both direct and indirect buddies; find an example of such a pair in the examples above.) We call the set of direct and indirect buddies the extended buddies of a person.

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

HINT: some of these methods will benefit greatly from designing a helper method first, that can be reused to help solve more than one of the questions above. You are encouraged to make a work-list for each problem, to figure out what the high-level steps are first, before diving into writing code without a plan.