Question: Create a class called Post representing a post that someone has made on a social media site. The Post must be able to record the

Create a class called Post representing a post that someone has made on a social media site.
The Post must be able to record the name of the author, the text of the post, the id of the post (an integer), the number of views, and the number of likes using private attributes.
Create a method for constructing a post given an id, author, and text.
Post must have methods for counting like, unlike, or viewing of the post. More specifically,
create a public void like() method. When called, the number of likes should be increased by one.
Likewise, create similar methods: view()
For unlike() decrease likes by one. Dont let the number of likes go below 0.
Create a method that prints the post.
Create a main program that creates an instance of Post and tests each of the methods. I am especially interested in how you will test unlike to make sure it does not go negative.
Suggested Test Case:
Create a post
Print the post
Call like() twice and view()3 times
Print the post
Call unlike()4 times
Print the post

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!