/****
* Class Friend has a name, email address,
* and up to 3 friends (other Friend objects)
*
* Below is the expected output of the complete program
* ------
* Name: Kenny Bania, Email:
* SueEllenMischke
* Sally Weaver
* JakeJarmel
*
* Name: Jake Jarmel, Email: SniffingAccountant812.gmail.com
* Sally Weaver
* SueEllenMischke
* Newman
*
* Name: Sally Weaver, Email:
* SueEllenMischke
* JackKlompus
* JakeJarmel
*
* Name: Jack Klompus, Email:
* Newman
* Sally Weaver
*
* Name: SueEllenMischke, Email:
* J Peterman
* Newman
* DavidPuddy
*
* Name: David Puddy, Email:
* Newman
* SueEllenMischke
*
* Name: Newman, Email:
* J Peterman
* DavidPuddy
* JackKlompus
*
* Name: J Peterman, Email:
* Newman
* SueEllenMischke
*
* Friends of Kenny Bania's friends are
* J Peterman
* Newman
* DavidPuddy
* SueEllenMischke
* JackKlompus
* JakeJarmel
* Sally Weaver
* SueEllenMischke
* Newman
*
* Friends of SueEllenMischke's friends are
* Newman
* SueEllenMischke
* J Peterman
* DavidPuddy
* JackKlompus
* Newman
* SueEllenMischke
*
* Mutual friends of Kenny Bania and Jake Jarmel
* SueEllenMischke
* Sally Weaver
*
* Mutual friends of Sally Weaver and Newman
* Jack Klompus
*
***/
public class Friend
{
private String name;
private String email;
Friend friend1;
Friend friend2;
Friend friend3;
/**
* Construct a Friend
*/
public Friend(String n, String e) {
name = n;
email = e;
friend1 = null;
friend2 = null;
friend3 = null;
}
/**
* Add a new friend to the list as follows.
* 1) Check to make sure friend is not already on the list.
* 2) If not already on the list the new friend gets added as
* friend1, the previous friend1 becomes friend2,
* and friend2 is moved down the list to friend3.
* 3) Adds "this" Friend to fnd's friends list,
* following rules 1 and 2 above.
*/
public void addFriend(Friend fnd) {
//< --- code NOT complete --- >
}
/**
* Return a list of the names of all friends:
* friend1's name
* friend2's name
* friend3's name
*/
public String getFriends() {
//< --- code NOT complete --- >
}
/**
* Return a list of the names of all of the friends of friends
* (the same name repeated is ok)
* Hint: use the getFriends method you already wrote
*/
public String friendsOfFriends() {
//< --- code NOT complete --- >
}
/**
* Return a list of the names of friends that this
* Friend and fnd have in common
*/
public String getFriendsInCommon(Friend fnd) {
//< --- code NOT complete --- >
}
/**
* Return information about the Friend:
* name, phone number, and list of friends names
*/
public String toString() {
//< --- code NOT complete --- >
}
public String getName() {
return name;
}
/***********************************************************
< the main method is complete and tests the above code >
************************************************************/
public static void main(String[] args)
{
Friend c1 = new Friend("Kenny Bania","");
Friend c2 = new Friend("Jake Jarmel","SniffingAccountant812.gmail.com");
Friend c3 = new Friend("Sally Weaver","");
Friend c4 = new Friend("Jack Klompus","");
Friend c5 = new Friend("SueEllenMischke","");
Friend c6 = new Friend("David Puddy","");
Friend c7 = new Friend("Newman","");
Friend c8 = new Friend("J Peterman","");
Friend c9 = new Friend("Crazy Joe Davola","PagliacciCrazy.gmail.com");
c1.addFriend(c2);
c1.addFriend(c3);
c1.addFriend(c5);
c2.addFriend(c7);
c2.addFriend(c5);
c2.addFriend(c3);
c3.addFriend(c4);
c3.addFriend(c5);
c5.addFriend(c6);
c5.addFriend(c7);
c5.addFriend(c8);
c7.addFriend(c4);
c7.addFriend(c6);
c7.addFriend(c8);
/**
* print out information about customers
*/
System.out.println(c1);
System.out.println(c2);
System.out.println(c3);
System.out.println(c4);
System.out.println(c5);
System.out.println(c6);
System.out.println(c7);
System.out.println(c8);
System.out.println("\nFriends of " + c1.getName() +
"'s friends are " + c1.friendsOfFriends());
System.out.println("\nFriends of " + c5.getName() +
"'s friends are " + c5.friendsOfFriends());
System.out.println("\nMutual friends of " + c1.getName() +
" and " + c2.getName() + c1.getFriendsInCommon(c2));
System.out.println("\nMutual friends of " + c3.getName() +
" and " + c7.getName() + c3.getFriendsInCommon(c7));
}
}