Question: For JAVA Write the implementation of the class NewsFeed . A NewsFeed object stores Post messages It uses a fixed size array of some constant
For JAVA
Write the implementation of the class NewsFeed. A NewsFeed object stores Post messages
It uses a fixed size array of some constant size MAX_SIZE to store Post messages . For this implementation will only accept up to 25 Post messages.
It has a method for adding a Post message. The message is added after the last message added.
It has a method sort in which the Post are sorted from the oldest to the most recent.
It has a method for returning the message found at a given index, Post get(int index).
It has a method size that returns the number of messages currently stored.
It has a method getPhotoPost that returns a new object of type NewsFeed containing only the PhotoPost
It has an instance method plus that has one formal parameter of type NewsFeed. This method returns a new object of type NewsFeed that represents the combination of the two NewsFeed. The Post of the new NewsFeed have to be sorted from the oldest to the most recent one





27 28 29 30 31 32 public int ize() { Use static array for NewsFeed * with constant MAX SIZE return size public void sort) 6 Epublic class NewsFeed int i, j, argMin; Post tmp private Postl messages; private int size public static final int MAX-SIZE 25; 34 35 36 37 38 39 40 41 42 43 for (j = i + 1 ; j { 5 protected int likes; private Date timeStamp; private String userName; 7 9 10 public Post (String userName) { this.userName-userName; 12 13 14 15 16 17 18 19 20 21 public String getUserName() return userName; public Date getTimestamp ) return timeStamp; public void like) ( likes-likes+1; 23 public int getLikes )I 25 26 27 28 29 30 31 32 return likes; // Implement the methods required by the interface Likeable // This file will not compile unless they are present with the correct name and si public String toString) l 3 4 35 3 6 37 38 3 9 String str - new String ) timeStamp - Calendar.getInstance ) .getTime ) str-getClass() . getName() + ": " + timestamp + '' , " + userName + '' , likes = " return str; public int compareTo (Post other) {
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
