Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You ll create three classes: Book, Library, and LibraryMain. Book The Book class keeps track of information about one book. The class should have the

Youll create three classes: Book, Library, and LibraryMain.
Book
The Book class keeps track of information about one book. The class should have the following fields:
title
author (just one String, dont use separate fields for first and last name)
length (an int, the number of pages in the book)
year (the year the book was published, also an int)
Add any constructors, get/set methods, or other methods that are helpful when writing the rest of the program.
Library
The Library class should have two fields: an array of Book objects called books, and an integer, numBooks, to keep track of how many books are in the array.
The Library class should have the following methods:
A constructor. The Library should have a constructor, which creates the books array, to hold 50 books, and then calls the loadLibrary method. You may have the filename written directly into the constructor (you dont need to ask the user for it).
private void loadLibrary(String filename). This method should open the file passed in as a parameter, and read the information about each book. The file format is:
AuthorFirstName AuthorLastName Length Year Title
with a space between each piece of information. Only the title may have spaces in it. For example:
Jane Austin 4801813 Pride and Prejudice
Read each book in from the file, and add it to the books array. You may assume that the file is correctly formatted (there wont be errors in the file). If there are more than 50 books in the file, it should stop after reading the 50 books and continue the rest of the program (without displaying an error).
public Book newest(). This method should return the book object of the newest/youngest. Note that this should return a Book object, not just a String with the name in it.
public double averageLength(). This method should return the average length of all books in the library. This should return a double, so be sure it doesnt round the correct answer to an integer.
public void searchForAuthor(String author). This method should search for the specified author, and display the titles, number of pages, and year for books of theirs in a neatly formatted table (you do not need to have a header at the top which labels the columns). If no books are found, display a message stating that there are no books by that author.
LibraryMain
The LibraryMain class will just have a main method in it. The main method should create a new Library class, and call the newest() method, displaying the name of the book and the year it was written in a natural sentence. It should then call the averageLength method, displaying that information in a natural sentence. Lastly, it should prompt the user to enter an author, and call searchForAuthor with that name.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions