In this project, you will experiment with building your own Python classes to work with existing classes (written by students in MCS-177). You will also work on unit testing and drawing UML diagrams.
Many of you log into Facebook and interact with your friends. Collaborating with MCS-177 students in your group, you will put together a program that represents a text-version of Facebook.
Here is an example of how all the classes come together to make our Facebook work.
>>> TextFacebook = Facebook()
>>> TextFacebook.registerUser('Bob', 'bob@gmail.com')
>>> TextFacebook.registerUser('Alice', 'alice@gac.edu')
>>> TextFacebook.registerUser('Charles', 'charlie@hotmail.com')
>>> TextFacebook.login('Bob')
>>> TextFacebook.addFriend('Alice')
>>> TextFacebook.postStatus('is working on Project 10!')
>>> TextFacebook.viewStatus()
(0) Bob is working on Project 10!
>>> TextFacebook.logout()
>>> TextFacebook.login('Charles')
>>> TextFacebook.addFriend('Alice')
>>> TextFacebook.postStatus('is going to watch Star Trek Into Darkness.')
>>> TextFacebook.viewStatus()
(1) Charles is going to watch Star Trek Into Darkness.
>>> TextFacebook.logout()
>>> TextFacebook.login('Alice')
>>> TextFacebook.viewProfile()
Alice (alice@gac.edu)
Friends: Bob and Charles
>>> TextFacebook.viewStatus()
(0) Bob is working on Project 10!
(1) Charles is going to watch Star Trek Into Darkness.
>>> TextFacebook.likeStatus(1)
>>> TextFacebook.viewStatus()
(0) Bob is working on Project 10!
(1) Charles is going to watch Star Trek Into Darkness.
Alice likes this.
>>> TextFacebook.commentOnStatus(0, 'Poor you... Have a cookie!')
>>> TextFacebook.viewStatus()
(0) Bob is working on Project 10!
Alice: Poor you... Have a cookie!
(1) Charles is going to watch Star Trek Into Darkness.
Alice likes this.
>>> TextFacebook.logout()
>>> TextFacebook.login('Bob')
>>> TextFacebook.viewStatus()
(0) Bob is working on Project 10!
Alice: Poor you... Have a cookie!
>>> TextFacebook.commentOnStatus(0, "It's all right. The project is a lot of fun!")
>>> TextFacebook.postStatus("finished working on Project 10! Woohoo!")
>>> TextFacebook.logout()
>>> TextFacebook.login('Alice')
>>> TextFacebook.viewStatus()
(0) Bob is working on Project 10
Alice: Poor you... Have a cookie!
Bob: It's all right. The project is a lot of fun!
(1) Charles is going to watch Star Trek Into Darkness.
Alice likes this.
(2) Bob finished working on Project 10! Woohoo!
First, carefully read this entire page, including the grading criteria at the bottom of the page.
The Comment (comment.py) class is going to be written by the MCS-177 students in your group. Please work with them to finish the code (you need their code in order to do task 3 and task 4 of this project). The implementation of the Comment class in comment.py is as follows:
Each comment object consists of the name of the commentor and the content.
The Comment class provides accessor and mutator methods for all instance variables.
The _ _str_ _ method of the Comment class returns a string that shows the name and the content separated by a colon. For example, Inigo Montoya's comment "I do not think it means what you think it means." should return a string shown below.
'Inigo Montoya: I do not think it means what you think it means.'
Once you had helped the MCS-177 students in your group to finish the Comment class (comment.py), you will need to make sure that the Comment class works and behaves the way you want it to (as you will need to later write code that works with the Comment class). Create a main.py class for unit testing for the Comment class. The example given above can be a part of your unit tests. Please be sure to cover all of the exception cases and give tests for at least two normal cases. You will also need to write comments labeling each of your test cases. Please work with the MCS-177 students in your group for the testing (as they also need to do these tests in their project).
Status (status.py) class is going to be written by the MCS-177 students in your group. The implementation of the Status class in status.py is as follows:
Each status object consists of the name of the person who posted the status, the status message, names of those who liked the status, and comment objects associated with the status.
The Status class provides accessor and mutator methods for all instance variables.
The Status class provides the following methods:
A method addLike which takes a name and adds the name to those who like the status.
A method addComment which takes a Comment object and adds the given comment.
The __str__ method of the Status class returns a string with the poster's name, the status message, the names of those who like the status and commments afterwards. The string should not have a newline character (\n) at the end. If multiple users liked the status, they should be comma separated. For example, if Alice and Bob liked the status, "Alice, Bob like this."
The following string is returned by a Status object whose poster is Ben Franklin and status message is 'signed the declaration of independence today. Booyah, England!'. France liked this Status object, and there are four Comment objects for the status.
'Ben Franklin signed the declaration of independence today. Booyah, England!\nFrance like this.\nJohn Adams: Bring it, bra.\nBen Franklin: You redcoats don't stand a chance.\nJohn Hancock: Does this mean we get to sign more? Cuz that was fun.\nBen Franklin: So we gathered.'
The output below shows when the above string is printed.
Ben Franklin signed the declaration of independence today. Booyah, England! France like this. John Adams: Bring it, bra. Ben Franklin: You redcoats don't stand a chance. John Hancock: Does this mean we get to sign more? Cuz that was fun. Ben Franklin: So we gathered.
Furthermore, the __str__ function which implements the line with people who like the status is gramatically correct. For example, "France likes this." and "France and Bob like this." and "France, Bob and Daniel like this.". You should inspect the __str__ function and make sure that you understand how it was able to do that.
Once you had helped the MCS-177 students in your group to finish the Status class (status.py), you will need to make sure that the Status class works and behaves the way you want it to (as you will need to later write code that works with the Status class). In the main.py class, add unit testing for the Status class. The example given above can be a part of your unit tests. Please be sure to cover all of the exception cases and give tests for at least two normal cases. You will also need to write comments labeling each of your test cases. Please work with the MCS-177 students in your group for the testing (as they also need to do these tests in their project).
Given the Comment class and the Status class that were provided to you. You are to implement the User class in user.py such that:
Each user consists of his/her name, e-mail address and list of friends (User objects). Only the name and e-mail address are required to create a User object.
The User class provides accessor and mutator methods for all instance variables.
The User class provides the following methods:
A method addFriend which takes a User object and makes both users friends of each other.
A method isFriend which takes a User object and returns True if the given user is a friend and False otherwise.
The __str__ method of the User class returns a string containg the name, e-mail address and the names of all friends. For example, if you print a user whose name is Jim Halpert, whose e-mail address is jim@office.com and whose only friend is Pam Beesley, the string should look as shown below.
'Jim Halpert (jim@office.com)\nFriends: Pam Beesley'
The output below shows when the above string is printed.
Jim Halpert (jim@office.com) Friends: Pam Beesley
If one has no friends, the output should be as shown below.
Chazz Michael Michaels (lonewolf@icerink) Friends: None
If one has more than one friend, the names of all the friends should belong to the same line as shown below.
Bob (bob@gmail.com) Friends: Alice, Charles, Daniel
Then, upgrade the format of the list of friends as shown below.
Bob (bob@gmail.com) Friends: Alice, Charles and Daniel Alice (alice@gmail.com) Friends: Bob and Charles
User class in your main.py. Please be sure to cover all of your exception cases and give tests for at least two normal cases. You will also need to write comments labeling each of your test cases.
Implement the Facebook class in facebook.py such that:
The facebook.py file starts with the following imports:
from comment import * from status import * from user import *
Facebook keeps track of all the users and their statuses and the currently logged-in user. Facebook object also keeps track of unique IDs for statuses. For the purpose of this project, only one user is allowed to use the Facebook at a time. When a Facebook object is created, it does not have any users or statuses.
Use a dict-of-string:user, where the keys are names and the values are user objects, to keep track of users in the Facebook class.
Use a list-of-status, where the positions in the list are status IDs and the values are status objects, to keep track of statuses in the Facebook class.
Use a string (the name of the current user) to keep track of who's currently using your Facebook.
You do NOT have to implement any accessors and mutators for the instance variables in the Facebook class.
You do NOT have to implement the __str__ method in the Facebook class.
For examples of outputs from the following methods, refer the the example at the top of this page. None of the following methods returns any value; all output is printed
The Facebook class provides a method called registerUser which takes a name and an e-mail address. This method adds a new user to Facebook. It should print an error message if there is already a user with the same name.
The Facebook class provides a method called login which takes a name. This method allows a person to log into Facebook with the user associated with the given name. If another user is logged in already, it should print out an error message saying that the other user needs to log off first.
The Facebook class provides a method called logout. This method allows the currently logged-in user to log out from Facebook. It should print out an error message if there is no user logged in at the time.
The Facebook class provides a method called addFriend that takes a name. This method allows the currently logged-in user to befriend the user with the given name. This should make both users friends of each other. It should print out an error message if there is no user logged in at the time; or if there is no other user with the given name.
The Facebook class provides a method called viewProfile. This method allows the currently logged-in user to view his/her profile that includes his/her name and email address along with the list of his/her friends.
The Facebook class provides a method called postStatus. This method allows the currently logged-in user to post a new status. Facebook should add this new status. It should print out an error message if there is no user logged in at the time.
The Facebook class provides a method called viewStatus. This method allows the currently logged-in user to view statuses of the user and his/her friends. If there is no user logged in at the time, it should not print any statuses and print out an error message saying that a user need to be logged in. The selected statuses should be printed in order of status ID number.
The Facebook class provides a method called likeStatus which takes a status ID number. This method allows the currently logged-in user to like his/her status or his/her friend's status. If there is no user logged in at the time, it should print out an error message. If the status the user tries to "like" is not his/hers or his/her friend's, it should also print out an error message.
The Facebook class provides a method called commentOnStatus which takes a status identification number and a comment (string). This method allows the currently logged-in user to comment on his/her status or his/her friend's status. If there is no user logged in at the time, it should print out an error message. If the status the user tries to "comment" is not his/hers or his/her friend's, it should also print out an error message.
Facebook class in your main.py. Please be sure to cover all of your exception cases and give tests for at least two normal cases. You will also need to write comments labeling each of your test cases.
Remember not to print anything in the __str__ method. You should accumulate ONE string that contains all the information and return it.
You will be submitting your code using Moodle. Be sure to select 2025 f-mcs-178-001, which is your lecture section, then click on the MCS-178 Project 7 Submission link. For this project, you will need to submit the following files:
User class.Facebook class.You will earn one point for each of the following accomplishments:
All exception cases and normal cases were tested in main.py for the Comment class; comments were given labeling each test case (5 pts).
All exception cases and normal cases were tested in main.py for the Status class; comments were given labeling each test case (5 pts).
All exception cases and normal cases were tested in main.py for the User class; comments were given labeling each test case (5 pts).
All exception cases and normal cases were tested in main.py for the Facebook class; comments were given labeling each test case (5 pts).
The overall UML diagram for the program is drew correctly (10 pts).
You have all the instance variables necessary for the User class (5 pts).
You have all the accessor and mutator methods for all the instance variables in the User class (5 pts).
The __str__ method in the User class formats the code correctly (5 pts).
The addFriend method links two users as friends correctly in the User class (5 pts).
The isFriend method checks if the given user is a friend or not correctly (5 pts).
The __str__ method of the user class uses the grammatically correct format (5 pts).
You have all the instance variables necessary for the Facebook class (5 pts).
The registerUser method adds a new user to Facebook correctly (5 pts).
The login and logout methods log in and out a user correctly and print out an error message when appropriate (5 pts).
The addFriend method correctly links two users as friends in the Facebook class (5 pts).
The viewProfile method displays the information about the current user correctly (5 pts).
The viewStatus method displays only the status of the currently logged-in user and his/her friends, formatting
the statuses correctly and printing out an error message when appropriate (5 pts).
The postStatus method adds a new post by the user correctly. It prints out an error message when appropriate (5 pts).
The likeStatus and commentOnStatus methods behave correctly. They print out an error message when appropriate (5 pts).