Publication and its subclasses

Report a typo

You are given four classes — Publication, Newspaper, Article and Announcement. You need to override the methods getType() and getDetails() in classes inherited from the class Publication. getType() should show the kind of publication, like a newspaper, and getDetails() should show the class attribute, such as the source.

Then you need to implement getInfo() in the class Publication using getType() and getDetails(). The method should return a String with a type of publication in the first place, then details in round brackets and the title after a colon. Examples are shown below.

Sample Input 1:

Publication; The new era

Sample Output 1:

Publication: The new era

Sample Input 2:

Newspaper; Football results; Sport news

Sample Output 2:

Newspaper (source - Sport news): Football results

Sample Input 3:

Article; Why the Sun is hot; Dr James Smith

Sample Output 3:

Article (author - Dr James Smith): Why the Sun is hot

Sample Input 4:

Announcement; Will sell a house; 30

Sample Output 4:

Announcement (days to expire - 30): Will sell a house
Write a program in Java 17
class Publication {

private String title;

public Publication(String title) {
this.title = title;
}

public final String getInfo() {
// write your code here
}

public String getType() {
return "Publication";
}

public String getDetails() {
return "";
}

}

class Newspaper extends Publication {

private String source;

public Newspaper(String title, String source) {
super(title);
this.source = source;
}

// write your code here

}

class Article extends Publication {
___

Create a free account to access the full topic