Question: JAVA -- PLEASE EXPLAIN WITH COMMENTS There are three classes including Book, Inventory and ShoppingCart, and two main classes to test the code including Main_Inventory

JAVA -- PLEASE EXPLAIN WITH COMMENTS

There are three classes including Book, Inventory and ShoppingCart, and two main classes to test the code including Main_Inventory and Main_ShoppingCart

In order to create a book, you need title, price, IBAN, quantity and author. The Book class must have toString() method for all variables. (1 point)

Inventory class has ArrayList of books, totalValue(the total value of the stock of all books on the shelf i.e quantity * price of the book) and must have toString() method for all variables (1 point)

The Inventory constructor should accept ArrayList of books

ShoppingCart class has attributes of customerName and date (string). ShoppingCart class must have methods to addBook(), removeBook(), searchInventory(), and viewCart(). (0.5 point)

Use binary search for searchInventory(). The quantity of the book in the inventory needs to be updated when an book is added or removed. (1 point)

The price of the book is retrieved from the book list. (0.5 point)

Before adding the book to the shopping cart, check the quantity in the inventory list first. If the quantity is less than what the customer wishes to purchase, print out a message that show the quantity available, and only sell the quantity in the inventory list. If the quantity in the inventory list is 0, print a message to tell customer the book is not available. (1 point)

Create an inventory list with the following information in the Main_Inventory. Print the content of the inventory list ( 1 point)

IBAN Title Quantity price author

"1000" "Harry Potter" 30 2.50 J.K. Rowling

"1001" "Great Gatsby" 40 2 F.Scott Fitzgerald

"2001" "Sherlock Holms" 10 2.39 Arthur Conan Doyle

"2002" "The little mermaid" 20 1.99 Hans Christian Anderson

"3001" "Twilight" 10 2.25 Stephanie Meyer

"3002" "The boy in the striped pyjamas", 20, 2.79, John Boyne

"4001" "Jane Eyre" 10 2.99 Charlotte Bronte

"4002" "The daVinci code" 30 0.99 Dan Brown

"5001" "Lord of the Rings" 10 5.00 J.R.R Tolkein

"5002" "Oliver Twist" 10 4.00 Charles Dickens

Create two shopping carts , cart1 and cart2, with the following information in the Main_ShoppingCart class

Print out the details and contents of cart1 and cart2. (1point)

Print out the inventory list after cart2 has finished shopping. (1 point)

Shuffle cart2 and sort cart2 by price in ascending order (1 point)

Cart1------------------------------------

cart1.addBook("Harry Potter", 2)

cart1.addBook("Great Gatsby", 5)

cart1.addBook("Sherlock Holms", 8)

cart1.addBook("Twilight", 4)

cart1.addBook("Jane Eyre", 25)

cart1.removeBook("Sherlock Holms", 5)

Cart2-------------------------------------

cart2.addBook("The boy in the striped pyjamas ", 2)

cart2.addBook("Oliver Twist ", 5)

cart2.addBook("Lord of the Rings ", 2)

cart2.addBook("Great Gatsby ", 4)

cart2.addBook("Twilight ", 3)

cart2.addBook("The daVinci code ", 6)

cart2.addBook("Harry Potter ", 20)

cart2.addBook("The little mermaid ", 10)

cart2.addBook("Jane Eyre ", 2)

cart2.removeBook("The little mermaid", 5)

cart2.removeBook("Lord of the Rings ", 1)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!