#Confirm you can add instances of EventPost to the newsfeed application and display it's fields.

5 messages · Page 1 of 1 (latest)

willow sand
#

So basically I have created a subclass EventPost to a given superclass Post. There is a another class called NewsFeed where I kinda run everything. But I don't really understand what is meant by "Confirm you can add instances of EventPost to the newsfeed application and display it's fields."? My guess in the main method of NewsFeed

import java.time.*;
public class EventPost extends Post{
   
    String title;
    String location;
    String date;
    public EventPost(String author, String title, String location, String date) {
        super(author);
        this.title = title;
        this.location = location;
        this.date = date;
    
    }

    public String getTitle(){
        return title;
    }

    public String location(){
        return location;
    }

    public String date(){
        return date;
    }

    public void display(){
        Post post = new post();
        System.out.println("[" + title + "]");
        System.out.println("location:" + location);
        System.out.println("Date:" + date );        
        post.display();

        super.display();
    }
  
}``` ```java
import java.time.LocalDate;
import java.util.ArrayList;
import java.time.Month;

public class NewsFeed {
    private ArrayList<Post> posts;

   
    public NewsFeed() {
        posts = new ArrayList<Post>();
    }

    public void addPost(Post post) {
        posts.add(post);
    }
    public void show() {
        // display all posts
        for(Post post : posts) {
            post.display();
            System.out.println();
        }
    }


    public static void main(String args[]) {
        NewsFeed app = new NewsFeed();
      
  
        LocalDate theDate = LocalDate.of(1989, 3, 14);
        app.addPost(new EventPost("Alice", "Living the life", "Mars", theDate));
        app.show();
    }
}
obsidian prismBOT
#

This post has been reserved for your question.

Hey @willow sand! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

grand dragon
#

Yeah you did it right they wanted you to proof that you can put obj of the type EventPost in an array of Post obj

#

but this part is wrong

public void display(){
        Post post = new post();
        System.out.println("[" + title + "]");
        System.out.println("location:" + location);
        System.out.println("Date:" + date );        
        post.display();

        super.display();
    }