In this project, you will continue to experiment with building your own Python classes. Many of you log into Facebook and interact with your friends. You will build classes to represent a text-version of Facebook.
This project is out of 20 points and offers up to 7 extra credit points once the project is complete. You can skip anything shown in blue and come back to finish it later for more credits.
We stongly encourage you to work on this project with a partner.
>>> 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!
Comment
class in comment.py
such that:
Comment
class provides accessor and mutator methods for all instance variables.
__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.'
Status
class in status.py
such that:
Status
class provides accessor and mutator methods for all instance variables.
Status
class provides the following methods:
addLike
which takes a name and adds the name to those who like the status.
addComment
which takes a Comment object and adds the given comment.
__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.
The output below shows when the above string is printed.
'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.'
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.
For more credit, make the line with people who like the status gramatically correct. For example, "France likes this." and "France and Bob like this." and "France, Bob and Daniel like this."
User
class in user.py
such that:
User
objects). Only the name and e-mail address are required to create a User
object.
User
class provides accessor and mutator methods for all instance variables.
User
class provides the following methods:
addFriend
which takes a User
object and makes both users friends of each other.
isFriend
which takes a User
object and returns True
if the given user is a friend and False
otherwise.
__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
For more credit, 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
Facebook
class in facebook.py
such that:
facebook.py
file with the following import
from comment import * from status import * from user import *
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.
dict-of-string:user
, where the keys are names and the values are user objects, to keep track of users in the Facebook class.
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.
string
(the name of the current user) to keep track of who's currently using your Facebook.
Facebook
class.
__str__
method in the Facebook
class.
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 return an error if there is already a user with the same name.
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.
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.
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.
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.
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.
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.
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.
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.
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; click on the following link for instructions on submitting code using Moodle. For this project, you will need to submit the following files:
Comment
class.Status
class.User
class.Facebook
class.You will earn one point for each of the following accomplishments: (Project 10 is still out of 20 points. In other words, you may earn up to 7 points of extra credits in this project.)
Comment
class.
Comment
class.
Comment
class accept only valid values and prints an error message for invalid values.
__str__
method in the Comment
formats the code correctly.
Status
class.
Status
class.
Status
class accept only valid values and prints an error message for invalid values.
__str__
method in the Status
class formats the code correctly.
addLike
and addComment
methods are implemented correctly.
User
class.
User
class.
User
class accept only valid values and prints an error message for invalid values.
__str__
method in the User
class formats the code correctly.
addFriend
method links two users as friends correctly in the User
class.
isFriend
method checks if the given user is a friend or not correctly.
Facebook
class.
registerUser
method adds a new user to Facebook correctly.
login
and logout
methods log in and out a user correctly and prints out an error message when appropriate.
addFriend
method correctly links two users as friends in the Facebook
class.
viewProfile
method displays the information about the current user correctly.
viewStatus
method displays only the status of the currently logged-in user and his/her friends.
viewStatus
method formats the statuses correctly and prints out an error message when appropriate.
postStatus
method adds a new post by the user correctly. It prints out an error message when appropriate.
likeStatus
and commentOnStatus
methods behave correctly. They print out an error message when appropriate.
__str__
method of the status
class uses the grammatically correct format.
__str__
method of the user
class uses the grammatically correct format.