Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA PROGRAMMING I NEED TO UPDATE THE CODE BELOW ACCORDING TO THE INSTRUCTIONS. PLEASE HELP ASAP I NEED IT IN COUPLE HOURS. thanks Please modify

JAVA PROGRAMMING

I NEED TO UPDATE THE CODE BELOW ACCORDING TO THE INSTRUCTIONS. PLEASE HELP ASAP I NEED IT IN COUPLE HOURS. thanks

Please modify Library.java to use a single ArrayList of Book objects called books. This list should be populated with values at the beginning of the main method. The rest of the code should be modified so that books is the only field used by the application -- all other arrays storing information about the books, renters, and due dates should be deleted and all code using those arrays should be modified to work with books instead.

Eliminate the getRenter, and bookExists methods. Write two new methods:

  • void initializeDatabase() - has no parameters and returns nothing. This method should initialize the list of books to contain the 10 books originally in the arrays that you should have replaced.
  • Book getBook(String bookName) - that takes a single String argument (the title of the book), searches through the books list for the book, and returns the appropriate book object (or null if the title was not matched).
  • Update the rest of thecode to rely on these methods. First, have initializeDatabase() be the first call your main method makes. Next, use a for-each loop over the books list in options #1 and #2. When the user looks for a book, call this method to retrieve a book object, store it in a local variable, and then use the methods of that book object to get details like the renter, author, dueDate, etc, rather than keeping an index and accessing the old arrays you deleted. Check to see if the variable holds the null value to see if the book exists or not. When you're finished, an index variable shouldn't ever by used in the main method anymore.
 package.... import java.time.LocalDate; import java.util.Scanner; public class Library { // the names of books in stock in the library private static final String[] booksInStock = new String[] { "The Left Hand of Darkness", "Dune", "Hitchhiker's Guide to the Galaxy", "Do Androids Dream of Electric Sheep?", "Frankenstein", "The Hunger Games", "Never Let Me Go", "Neuromancer", "I Robot", "Snow Crash" }; // the authors of books in stock in the library private static final String[] authors = new String[] { "Ursula Le Guin", "Frank Herbert", "Douglas Adams", "Philip K. Dick", "Mary Shelly", "Suzanne Collins", "Kazuo Ishiguro", "William Gibson", "Isaac Asimov", "Neil Stephenson" }; // the names of renters of each of the books (indexes line up) // null indicates the book is currently at the library private static final String[] renters = new String[booksInStock.length]; // dates that each book was rented private static final LocalDate[] dueDates = new LocalDate[booksInStock.length]; /** returns the renter associated with the book name. * If no one is renting the book, null is returned. * @param bookName * @return */ public static String getRenter(String bookName) { for(int i=0; i                        

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_2

Step: 3

blur-text-image_3

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

Big Data Concepts, Theories, And Applications

Authors: Shui Yu, Song Guo

1st Edition

3319277634, 9783319277639

More Books

Students also viewed these Databases questions

Question

1.who the father of Ayurveda? 2. Who the father of taxonomy?

Answered: 1 week ago

Question

Commen Name with scientific name Tiger - Wolf- Lion- Cat- Dog-

Answered: 1 week ago

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago