Question: Could anyone help me with this Java assignment please? Objectives: To use our knowledge of collections to build a simple library system. Assignment: Your job
Could anyone help me with this Java assignment please?
Objectives: To use our knowledge of collections to build a simple library system. Assignment: Your job is to build other classes that support the following class LibraryTest: public class LibraryTest { private static void printInventory(Library lib) { for (LibraryItem li : lib.getMaterials()) { System.out.println("Item: " + li); } } public static void main(String[] args) { Library myLibrary = new Library(); myLibrary.addBook("Wonder"); myLibrary.addBook("Curious George", 3); myLibrary.addDvd("Star Wars", 2); printInventory(myLibrary); Book b = myLibrary.findBook("Wonder"); if (b != null) { myLibrary.checkout(b); } Dvd d = myLibrary.findDvd("Star Wars"); if (d != null) { myLibrary.checkout(b); } Dvd d = myLibrary.findDvd("Zootopia"); if (d != null) { myLibrary.checkout(b); } printInventory(myLibrary); } } Output: Running the above code plus your classes, will generate the following output: Current inventory ======================== Item: Wonder (Book) Item: Curious George (Book) Item: Curious George (Book) Item: Curious George (Book) Item: Star Wars (DVD) Item: Star Wars (DVD) Current inventory ======================== Item: Curious George (Book) Item: Curious George (Book) Item: Curious George (Book) Item: Star Wars (DVD) Key notes: Library, LibraryItem, Book, Dvd should all be separate classes Use an ArrayList to implement Library; you should use an ArrayList for each item type. Thus, the main 2 private members variables of Library are both ArrayList objects, one that holds books, one that holds DVDs. The Library addBook()and addDvd() methods should take the String name and optionally the number of copies of that item (you will need to overload the addBook and addDvd methods). o When they are callled, they should create a Book or Dvd object accordingly, and add it to the proper internal ArrayList o If multiple copies are specified, you will need to create as many objects as is requested, adding them to the array one at a time The findDvd() and findBook() methods should search the proper ArrayLIst and return the first object matching the name requested (if any) Checking out a book or a DVD removes the item from the ArrayLiist Make sure that LibraryItem is the superclass of Book and Dvd Make sure that LibraryItem has a String name (which has getters and setters) o Book and Dvd should call the superclass constructor
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
