Question
JAVA CODE PLEASE You will be coding the VideoPost, PollPost, MessagePost, Comment classes. You need to determine which of these classes should subclass Post. Feel
JAVA CODE PLEASE
You will be coding the VideoPost, PollPost, MessagePost, Comment classes.
You need to determine which of these classes should subclass Post. Feel free to completely refactor the Post class to make effective use of method overrides and overloads. You can assume an instance of Post will never be used in the PostWall, i.e. it will always be a VideoPost, PollPost, or MessagePost. In the future, Post would be a good candidate for an interface. In general, you should always code against an interface when implementing your polymorphic behaviour. But this is a topic for a future lab.
While inheritance is a viable strategy for this lab, composition could be a better solution. We will stick to inheritance for this lab because we want to be able to handle Post objects in a polymorphic manner within the PostWall class (we want to be able to call display() across all Posts on the wall).
- Comment:
- This is a class that will be used to model comments. Comments get displayed on other posts, never on their own.
- A Comment has a message (could be content), an author, and a time.
- A Comment cannot be commented on. A Comment cannot be reacted to.
- VideoPost:
- This subtype of Post is very similar to its superclass. A disclaimer should be displayed above the entire post (i.e. on top of it). The disclaimer should say "VIEWER DISCRETION ADVISED" if it is set when the VideoPost is instantiated.
- Content in a VideoPost will be a url. These should simply be Strings.
- PollPost:
- This subtype of Post is different in that it can be "reacted" to in two ways. This post should still be displayed with the emoji counters, but users can also submit a String answer. These will typically be a single word and can be anything!
- A PollPost should have a poll question and answers to the poll question as its content section.
- Notice the answers contain a count next to them, and they are not sorted. You can use the StringIntPair class provided to simplify your collection of poll answers in PollPost.
- MessagePost:
- This subtype of Post should essentially be the Post class you created in section 2.0. It should have a message as content and display identically to the Post class from section 2.0.
A call to PostWall.generate() with an example of each type of post is displayed below for reference. Chris Mascarolls on (Sun Dec 06 14:24:06 EST 2020): 'Deck the halls.' =)(32) =|(13) =((1) =O(0) Comments: -> 'What are your plans?!' - Wanda Nauwittol (Sun Dec 06 14:24:06 EST 2020) -> 'Yay!' - Jude Alkingtomie (Sun Dec 06 14:24:06 EST 2020) -> 'Nope!' - Grinch Grinch (Sun Dec 06 14:24:06 EST 2020) -------------------------------------------------- -VIEWER DISCRETION ADVISED- Grinch Grinch on (Sun Dec 06 14:24:06 EST 2020): 'This bumps! https://www.youtube.com/watch?v=GAs67cRfmQI&ab_channel=Tyler%2CTheCreator-Topic' =)(1) =|(13) =((0) =O(0) Comments: -------------------------------------------------- Wanda Nauwittol on (Sun Dec 06 14:24:06 EST 2020): 'What's everyone doing for Christmas Break!?' Eat! (2) Eat (1) Celebrate (2) Not study! (3) =)(5) =|(3) =((1) =O(0) Comments: -> 'Yes.' - Jude Alkingtomie (Sun Dec 06 14:24:06 EST 2020) -> 'Nothing... >:)' - Grinch Grinch (Sun Dec 06 14:24:06 EST 2020) --------------------------------------------------
COMMENT CLASS
public class Comment { // member variables private Date time; private String author; private String content; // Getter functiond public Date getTime() { return this.time; } public String getAuthor() { return this.author; } public String getContent() { return this.content; } // Constructor public Comment(String author, String content) { this.content = content; this.author = author; this.time = java.util.Calendar.getInstance().getTime(); } // Function to return comments in proper format as string public String display() { /*TODO*/ String s = String.format( "->'%s' - %s (%s): " , this.getContent(), this.getAuthor(), this.getTime() // add the required values here ); return s; } }
POST CLASS
import java.util.*; // Defination of Post class public class Post { // member variables private String comments; private String author; private String post; private Date time; private int happy; private int sad; private int surprised; private int blank; public Post(){ this.comments = ""; this.author = ""; this.post = ""; this.time = java.util.Calendar.getInstance().getTime(); this.happy = 0; this.sad = 2; this.blank = 1; this.surprised = 3; } public Post(String author, String post) { this.author = author; this.post = post; this.time = java.util.Calendar.getInstance().getTime(); this.comments = ""; } // Getter functions. public String getComments() { return this.comments; } public String getAuthor() { return this.author; } public String getPost() { return this.post; } public Date getTime() { return this.time; } public int getHappy() { return this.happy; } public int getSad() { return this.sad; } public int getSurprised() { return this.surprised; } public int getBlank() { return this.blank; } // React function to add reactions public void react(int reaction) { if (reaction == 0) this.happy++; else if (reaction == 1) this.blank++; else if (reaction == 2) this.sad++; else if (reaction == 3) this.surprised++; } public void addComment(Comment comment) { this.comments += comment.display(); } // Funtion to display the post public void display() { /*TODO*/ String s = String.format( "%s on (%s): " + "'%s' " + "=)(%d) =|(%d) =((%d) =O(%d) " + "Comments: " + "%s" , this.getAuthor(), this.getTime(),this.getPost(), this.getHappy(), this.getBlank(), this.getSad(), this.getSurprised(), this.getComments() // add the required values here ); System.out.println(s); } }
POSTWALL CLASS
import java.util.ArrayList; public class PostWall { private ArrayList posts; public PostWall() { posts = new ArrayList<>(); } public void generate() { for (Post post : posts) { post.display(); System.out.println("---------------------------------------------------------------------------"); } } public void addPost(Post post) { posts.add(post); } }
STRINGINTPAIR CLASS
public class StringIntPair { public final String s; public final int i; public StringIntPair(String s, int i) { this.s = s; this.i = i; } }
WHAT DO YOU MEAN BY INPUT AND OUTPUT?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started