diff_months: 20

Create and complete the Stock Database class

Download Solution Now
Added on: 2022-11-04 09:33:29
Order Code: 474340
Question Task Id: 0
  • Country :

    Australia

Tracking Items in a Warehouse
Now that we have a way of representing items, we need a way of collecting them together and keeping track of them all. To do this we will create a class called StockDatabase which will keep track of which items are in the warehouse, how many of them there are, adding items to the warehouse, removing items from the warehouse and stocking and selling items (using the Item class to do as much of the work as possible). To help deal with exceptional cases, we will also create some new Exceptions - a DuplicateItemIDException and an ItemNotFoundException.

The Skeleton
You begin with a solution to the previous task - a complete Item class and an InvalidQuantityException.

The Exceptions
You will need to create two exception classes, DuplicateItemIDException and ItemNotFoundException. In the workspace you have an example of the the InvalidQuantityException from the previous task - they don't have to even be that complicated though, an absolutely basic exception will work for what we need here.

The StockDatabase
The main work of this task is in creating and completing the StockDatabase class. As with the previous task, you will need to create the file for StockDatabase, which will be a public class.

  • StockDatabase will should have a field of type Item[] called items, which will contain the Items. items should be private. StockDatabase should have no public fields, but if you like you can add other private fields (and for this one, it's probably necessary). Note that you will need, at points, to implement code to keep track of how much of the array is in use, and to expand the array if necessary.
  • StockDatabase should have a single public constructor. It should have no parameters, and initialises items to length 10 (and whatever else your implementation requires).
  • StockDatabase should also have the following public methods:
  • addItem which takes a single Item as a parameter and adds it to the items array. This should throw a DuplicateItemIDException if there is already an Item in the warehouse with the same id.
  • removeItem which takes a String as a parameter representing the id of the item to remove. If the item is in the warehouse, it should be removed completely. Depending on your implementation, you may need to move things around the warehouse (i.e. move things in items). If the item is not present, it should do nothing.
  • sell, which takes a String for the id of the item to sell, and an amount to sell. This should reduce the quantity of that item by the amount sold. If the item is not present, throw an ItemNotFoundException, and if the quantity is not feasible, an InvalidQuantityException (this should require very little work if you're paying attention).
  • restock which takes a String for the id of the item to restock, and an amount to restock by. This should increase the quantity of that item by the restock amount. If the item is not present, throw an ItemNotFoundException, and if the quantity is not feasible, an InvalidQuantityException.
  • toString, which takes no parameters and returns a String representation of the object which has Stock Database: as a header line, then each Item as a String on a separate line. The items should appear in the order they were added.
  • StockDatabase should have no other public methods (though it is definitely useful to add private helper methods in this task).
  • You should not import any library code (this task would be trivial using any implementation of java.util.List - in fact, this task is building a simplified implementation of List, with the names changed).
  • Uploaded By : Katthy Wills
  • Posted on : November 04th, 2022
  • Downloads : 0
  • Views : 168

Download Solution Now

Can't find what you're looking for?

Whatsapp Tap to ChatGet instant assistance

Choose a Plan

Premium

80 USD
  • All in Gold, plus:
  • 30-minute live one-to-one session with an expert
    • Understanding Marking Rubric
    • Understanding task requirements
    • Structuring & Formatting
    • Referencing & Citing
Most
Popular

Gold

30 50 USD
  • Get the Full Used Solution
    (Solution is already submitted and 100% plagiarised.
    Can only be used for reference purposes)
Save 33%

Silver

20 USD
  • Journals
  • Peer-Reviewed Articles
  • Books
  • Various other Data Sources – ProQuest, Informit, Scopus, Academic Search Complete, EBSCO, Exerpta Medica Database, and more