Lab 16: Social Graphs
Intro
You’ll work in this lab with your ad-hoc partner.
The two of you will work as a team to solve problems. At any time, one of you will be the Head and the other will be the Hands. The Head does the thinking and the Hands does the typing. Hands type only what the Head tells them to, but you’re free to discuss any issues that pop up. You should switch off during the lab to make sure each of you get practice problem solving, dealing with syntax, and getting finger exercises on the keyboard.
You can start this lab with this project skeleton. (Yes, it’s called lab 18.)
Recall
In Lab 16: Social Graphs we learned how to handle cycles in simple lists.
In this lab, we’ll see cycles appear in a social network. To handle these cycles, we’ll practice writing accumulating operations over a graph of buddies.
A Person with Buddies
This lab focuses on a small group of friends named Alice, Bob, Carol, Donald, and Ester. Each person has a name a few people they consider their buddies. The class Person models a person with buddies.
We asked each of these five people to tell us their buddies. The results of that survey are shown here:
+--------+ |
--->| Carol |<------- |
/ +--------+------ \ |
/ ^ | \ \ |
/ | v v \ |
+--------+ +--------+<---+--------+ |
| Bob |--->| Alice | | Donald | |
+--------+ +--------+ +--------+ |
| |
v |
+--------+ |
| Ester |-- |
+--------+ \ |
^ / |
\_/ |
The arrow from Alice to Ester means that Alice said Ester was her buddy. Note: there is no arrow from Ester to Alice, so Ester does not include Alice in her list of buddies.
Ex 1: In the file Lab18.java, implement Main.initData such that the five friends are initialized with the buddies given in the above graph.
Direct Buddies
We call the people listed in some Person’s buddies the direct buddies. The buddies of your buddies are indirect buddies.
Ex 2: Some people technically qualify as both direct and indirect buddies. Find an example of such a pair in the social graph above.
Ex 3: Design the method Person.hasDirectBuddy(Person that), which returns true if the given person is a direct buddy of this person. Write at least two tests for each of our example people: one that returns true and one that returns false.
Ex 4: Design the method Person.countCommonBuddies(Person that), which returns the number of direct buddies shared by this and that person. Write at least one test for each of our example people.
Extended Buddies
If we’re throwing a party, we need to invite our buddies, their buddies, and their buddies’ buddies, etc. We call the set of all direct and indirect buddies the extended buddies of a person.
Ex 5: Design the method Person.hasExtendedBuddy(Person that), which returns true only if the given person is one of this person’s buddies or buddies’ extended buddies. Write at least one test returning true and one test returning false for each example person.
Ex 6: Design the method Person.partyCount(), which returns the number of extended buddies that would be invited to a party thrown by this person. Note: the party technically includes this person, so make sure not to leave them out when calculating the partyCount! Write a test for each of our example people.
Submission
Submit a zip file of your work at the end of lab.