Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

java problem A start-up company named Gazouillis wants to implement a breakthrou

ID: 3790342 • Letter: J

Question

java problem

A start-up company named Gazouillis wants to implement a breakthrough software system to exchange text and photographic messages. You have been tasked to create the prototype implementation that will be demonstrated to the investors.

This UML diagrams give you an overview of this application. Follow the instructions below:

1- Likeable

Implement the interface Likeable. It declares two methods: like() and int getLikes().

2- Post

Write the implementation of the class Post. It implements the characteristics that are common to its sub-classes, here TextPost and PhotoPost.

Post implements the interface Likeable.

All the Post messages have a user name, a time stamp (of type java.util.Date), as well as a count for the number of likes.

The value of the time stamp is automatically assigned when an object is created. Use java.util.Calendar.getInstance().getTime() to obtain a Dateobject representing the current time. A Date object has a method toString() that converts this date to a String

Each call to the method like() increases the number of likes for this message.

Post implements the interface Comparable. This interface allows you to compare two Post according to specific criteria. In this case the criteria will be the date of the post. For more information, refer to the documentation.

Add the method isPopular. This method returns true if the post is considered popular (more the 100 likes), false otherwise.

Do not forget the method toString()!

3- PhotoPost

Implement the class PhotoPost. A PhotoPost is a specialized Post. It stores a file name and a caption. Override the method toString() by using the keyword "super" in your implementation.

4- TextPost

Implement the class TextPost. A TextPost is a specialized Post. It stores a text message (String). Override the method toString using the keyword “super” in your implementation. A TextPost is considered popular if the post gets more than 50 likes.

5- NewsFeed

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.

Bonus

Write the implementation of the class NewsFeed using a dynamic array (array that automatically changes size) to store Post messages, instead of a fixed size array.

The constructor has two parameters, the initial capacity of the array and the capacity increment

Each time the array is full, the implementation should create a new array larger by the capacity increment.

Comparable Post Likeable NewsFeed Text Post PhotoPost

Explanation / Answer

public c l a s s Test {
public s t a t i c void main ( S t ri n g [ ] a r g s ) {
NewsFeed me s sa ge s ;
Post msg1 , msg2 ;
me s s age s = new NewsFeed ( 1 0 0 , 1 0 ) ;
msg1 = new PhotoPost ( "David" , "funny.png" , "Birthday party" ) ;
msg1 . l i k e ( ) ;
me s s age s . add ( msg1 ) ;
msg2 = new TextPost ( "David" , "Dinner at your place with Alexe" ) ;
msg2 . l i k e ( ) ;
msg2 . l i k e ( ) ;
me s s age s . add ( msg2 ) ;
me s s age s . add (new TextPost ( "Nancy" , "Okay" ) ) ;
for ( int i =0; i<me s s age s . s i z e ( ) ; i++) {
System . out . p r i n t l n ( me s s age s . g e t ( i ) ) ;
}
}
}