In this project, you will be implementing a simple social network. There are two classes you must implement. A Person object represents a single person. A SocialNetwork is a collection of Person objects, with some additional useful methods.
Implement the Person class with the following constructors and instance methods:
Constructs a new Person, with the name "Anon" concatenated with the next available unique number, starting with 1. For example, the first time a new Person() object is created, the name should be "Anon1", followed by "Anon2", "Anon3" etc... (HINT: You will need a static field to keep track of the "anon number".)
A newly constructed Person has no friends in their friend list.
public Person(String name)
Constructs a new Person with the name name.
public Person(Person p)
Constructs a new Person copied from Person p (does not have to be a deep copy).
public String getName()
Return the name of the Person
public void setName(String name)
Set the name of the person to name.
public void addFriend(Person p)
Add Person p to this Person's friendList and add this Person to p's friendList; do not add duplicates. (If this Person is already on p's friendList, do not add them again, and vice-versa).
If p == this, do nothing. (i.e. you should not be added to your own friendList)
public boolean deleteFriend(Person p)
Delete p from this Person's friend list and delete this Person from p's friend list.
Return true if and only if p was found on this Person's friend list (i.e. trying to delete a friend that does not exist should do nothing and return false.)
public boolean deleteFriend(String frenemyName)
Delete the first instance, p, of a Person with the name frenemyName from this Person's friend list and delete this Person from p's friend list.
Return true if and only if p was found on this Person's friend list.
public ArrayList<Person> getFriendList()
Return a shallow copy of this person's friend list - a new ArrayList, that references the same Person objects.
public ArrayList<Person> getFriendsOfFriends()
Returns a list of friends of friends of this person. The list should not contain this Perons's immediate friends, nor this Person.
Return the Person's name
public static int numberOfMutualFriends(Person p, Person q)
This static method should return the number of friends shared by both p and q.
You must create a SocialNetwork class that has a single public field: an ArrayList of Person objects called "users".
Implement the following methods:
public String toString()
Return a string wherein each line is a user's name followed by the names of their friends in the form "<name> is friends with <friendName1>, <friendName2>, <friendName3>\n". Note that this string ends without a comma, and creating such a string is a bit tricky.
public static Person friendRecomendation(Person p)
Returns a Person who is a friend of a friend of p, but not a friend of p. If multiple such Persons exist, it returns the one with the lexicographically smaller name. If no such person exists, it returns null.
For example, if Alice is friends with Bob, and Bob is friends with Clarence and Jane, the friendRecommendation() method should return "Clarence".
In addition, you should also implement a constructor for the SocialNetwork class that initializes the "users" field with an empty ArrayList.