26.6k views
1 vote
Improve the Database class ( I have attempted a few of these but unsure if they are correct.

a) Modify the addPublication method such that it checks, before adding a publication into publicationList, if it is already in the list. If so, it should instead print out an appropriate message with the details of the given publication.
b) Write a method that returns a list of books written by a given author.
c) Write a method that takes two parameters of int type, month and year, and returns the number of journals published in the given year and month.
d) Improve the method printList to print out the details of all publications ordered on the category of the publications, and then on the title within each category. Note: currently there are only 2 categories, i.e. Book and Journal, but the project may be expended by adding other categories, e.g. Newspaper etc.

User Skamielina
by
8.0k points

1 Answer

6 votes

Final answer:

This answer provides step-by-step explanations on how to improve the Database class by modifying the addPublication method, implementing a method to return books by a given author, creating a method to count journals published in a specific month and year, and improving the printList method to order publications by category and title.

Step-by-step explanation:

a) To modify the addPublication method, you can first check if the given publication is already in the publicationList. You can do this by iterating over the list and comparing each publication's details with the details of the given publication. If a match is found, you can print an appropriate message with the publication details. Otherwise, you can add the publication to the list as usual.

b) To return a list of books written by a given author, you can iterate over the publicationList and check if each publication is a book and if its author matches the given author. If a match is found, you can add the book to a separate list and return it.

c) To count the number of journals published in a given year and month, you can iterate over the publicationList and check if each publication is a journal and if its publication date matches the given year and month. If a match is found, you can increment a counter variable.

d) To improve the printList method, you can first sort the publicationList based on the category of the publications. Then, within each category, you can further sort the publications based on their title. Finally, you can iterate over the sorted list and print out the details of each publication.

User The Moisrex
by
7.5k points

No related questions found