Thursday, October 7, 2010

HW 5: The Social Network

In light of the popularity of that movie and thus the upcoming demise of its subject (we all know that if Hollywood makes a movie about a computer-related innovation that said innovation is on its way out, see AOL and Virtual Reality) for this homework you will build the a few simple classes for a social network application.

Specifically, you will have Persons, each of whom has a name, a status that is either SINGLE, MARRIED, UNKNOWN, or ITS_COMPLICATED, as well as his own FriendsList and Wall on which others can post messages. A Person should have methods for adding a friend X, when we do this then that person is also added to X's friend list (that is, both are now each other's friend). Two persons with the same name (regardless of case) are the same person. Each person appears as a friend only once; trying to add the same person more than once does not do anything. A person can also un-friend other persons, thereby removing both parties from their respective FriendsLists.

We can also add posts to each person's wall, each post has a corresponding author (a Person). Only someone who is a friend of the Person can post on that person's wall.

You can assume that a person has a maximum of 1024 friends, and a maximum of 1024 posts on his wall.

Finally, you will also implement all the appropriate toString methods.

For example, the following code:

 public static void main(String[] args) {
  Person mark = new Person("Mark Zuckerberg",Status.SINGLE);
  Person cam = new Person("Cameron Winklevoss",Status.ITS_COMPLICATED);
  Person tyler = new Person("Tyler Winklevoss",Status.MARRIED);
  Person tyler2 = new Person("tyler winklevoss",Status.UNKNOWN);
  Person peter = new Person("Peter Thiel",Status.UNKNOWN);

  System.out.println(mark);

  mark.addFriend(cam);
  mark.addFriend(tyler);
  mark.addFriend(tyler); //adding it for a SECOND time, so it does not get added
  mark.addFriend(tyler2); //tyler2 does not get added because he has the same name as tyler
  System.out.println(mark); //mark has 2 friends
  System.out.println(tyler); //tyler has 1 friend
  


  mark.addWallMessage("Hello there! We have a project for you!", tyler);
  mark.addWallMessage("Yeah, its a Harvard-only friendster", cam);
  tyler.addWallMessage("Cool, I'll work on it", mark);
  
  System.out.println(mark);
  System.out.println(tyler);
  
  mark.addWallMessage("Hey, how is our social website coming?", cam);
  cam.addWallMessage("Its going to take some time, I got finals", mark);

  peter.addFriend(mark);
  peter.addWallMessage("I made this cool website, want to fund me?", mark);
  mark.addWallMessage("Sure", peter);
  
  mark.addWallMessage("Wait a minute! We paid you to build that!", cam);
  cam.addWallMessage("Nah hah", mark);
  mark.addWallMessage("Yeah ha", cam);
  cam.addWallMessage("I'm unfriending you and your twin", mark);
  
  mark.removeFriend(cam);
  mark.removeFriend(tyler);
  System.out.println(mark); 
  System.out.println(tyler);
  System.out.println(cam);
  System.out.println(peter);
  
  mark.addWallMessage("I'm going to sue you in federal court!", cam);
  
  System.out.println(mark);
  
 }

should print out:
Mark Zuckerberg SINGLE
0 Friends:
Wall:


Mark Zuckerberg SINGLE
2 Friends:
Cameron Winklevoss
Tyler Winklevoss
Wall:


Tyler Winklevoss MARRIED
1 Friends:
Mark Zuckerberg
Wall:


Mark Zuckerberg SINGLE
2 Friends:
Cameron Winklevoss
Tyler Winklevoss
Wall:
Cameron Winklevoss writes:
Yeah, its a Harvard-only friendster
Tyler Winklevoss writes:
Hello there! We have a project for you!


Tyler Winklevoss MARRIED
1 Friends:
Mark Zuckerberg
Wall:
Mark Zuckerberg writes:
Cool, I'll work on it


Mark Zuckerberg SINGLE
1 Friends:
Peter Thiel
Wall:
Cameron Winklevoss writes:
Yeah ha
Cameron Winklevoss writes:
Wait a minute! We paid you to build that!
Peter Thiel writes:
Sure
Cameron Winklevoss writes:
Hey, how is our social website coming?
Cameron Winklevoss writes:
Yeah, its a Harvard-only friendster
Tyler Winklevoss writes:
Hello there! We have a project for you!


Tyler Winklevoss MARRIED
0 Friends:
Wall:
Mark Zuckerberg writes:
Cool, I'll work on it


Cameron Winklevoss ITS_COMPLICATED
0 Friends:
Wall:
Mark Zuckerberg writes:
I'm unfriending you and your twin
Mark Zuckerberg writes:
Nah hah
Mark Zuckerberg writes:
Its going to take some time, I got finals


Peter Thiel UNKNOWN
1 Friends:
Mark Zuckerberg
Wall:
Mark Zuckerberg writes:
I made this cool website, want to fund me?


ERROR: Cameron Winklevoss is not a friend of Mark Zuckerberg
Mark Zuckerberg SINGLE
1 Friends:
Peter Thiel
Wall:
Cameron Winklevoss writes:
Yeah ha
Cameron Winklevoss writes:
Wait a minute! We paid you to build that!
Peter Thiel writes:
Sure
Cameron Winklevoss writes:
Hey, how is our social website coming?
Cameron Winklevoss writes:
Yeah, its a Harvard-only friendster
Tyler Winklevoss writes:
Hello there! We have a project for you!

When done, submit all your files to our dropbox and do so by Tuesday, October 19 @9am.

1 comment:

Robert said...

Bonus points to the person who loses the least amount of hair by the end of the assignment. ;) j/k This oughta be fun.