Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CODE IN JAVA PLEASE In this problem you will be coding the PostWall class. A PostWall object is composed of (or an aggregation of) many

CODE IN JAVA PLEASE

In this problem you will be coding the PostWall class.

A PostWall object is composed of (or an aggregation of) many Post objects. These Post objects should be arranged in a vertical fashion, separated by a divider.

PostWall has some methods:

  • generate()
    • This method should generate the current "wall" made up of all the posts contained in the PostWall object.
    • It should be printed out vertically, by calling each Post's display() method. Posts should be separated by a divider.
  • addPost()
    • This method must take a Post object and add it to the PostWall's list of Posts.
    • Remember, a post can be any of the above Post subtypes (VideoPost, MessagePost, PollPost).

BELOW IS THE CODE FOR POST

import java.util.*; // Defination of Post class public class Post { // member variables private String comments; private String username; private String post; private Date time; private int happy; private int sad; private int surprised; private int blank; public Post(String username, String post) { this.username = username; 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.username; } 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); } }

comment class

import java.util.Date; 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; } } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions

Question

e. What do you know about your ethnic background?

Answered: 1 week ago

Question

How flying airoplane?

Answered: 1 week ago

Question

13-6 How will MIS help my career?

Answered: 1 week ago

Question

13-4 What are alternative methods for building information systems?

Answered: 1 week ago