Question
Java. Write a method that prints out the details of all publications published in a given year. The output should be ordered on the category
Java.
Write a method that prints out the details of all publications published in a given year. The output should be ordered on the category of the publications, and then on the title within each category. (Note: there are 3 categories: journals, books, and travel guidebooks.)
I have a Publication is a supper class of journals, books, and travel guidebooks. in my Publication, I have the getYear method and getTitle.
I have another class that has an array where all the Publication is a store.
public class Database {
private ArrayList publicationList;
public Database() { publicationList = new ArrayList(); }
public void addPublication(Publication newPublication) { if(newPublication != null){ publicationList.add(newPublication); } }
public void printYear(int enterYear) {
// code for sorting array goes here.
}
}
public class Publication { private String title; private int year; public Publication(String title, int newYear) { this.title = title; year = newYear; } public String getTitle() { return title; } public void print() { System.out.println("Name: " + title + "Address: " + year); } public int getYear() { return year; } public String toString() { return title + " Year: " + year; } }
public class TravelGuide extends Book { private String country; public TravelGuide(String title, String author, String publisher, int year, String country) { super(title,author,publisher, year); this.country = country; } public String getCountry() { return country; } public String toString () { return "Travel Guide " + super.toString() +" Country: " + country; } }
public class Book extends Publication {
private String author; private String publisher;
public Book(String title, String author, String publisher, int year) { super(title, year); this.author = author; this.publisher = publisher; }
public String getAuthor() { return author; } public void print() { super.print(); System.out.println("Name: " + author); }
public String getPublisher() { return publisher; }
public String toString () { return "Book: " + super.toString() + " Author: " + author + " Publisher: " + publisher; } }
public class Journal extends Publication { private int month;
public Journal(String title, int month, int year) { super(title, year); this.month = month; }
public int getMonth() { return month; }
public String toString() { return "Journal: " + super.toString() + " Month: " + getMonthName(month); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started