Package cs2110
Class Store
java.lang.Object
cs2110.Store
A mutable data structure that represents the current inventory of a grocery store. Items are
stored and accessed by their item codes.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
hasInStock
(long itemCode) Returns whether there is an item in the store's inventory with the given itemCode.void
Inserts this item into the store's inventory.unshelve
(long itemCode) Removes and returns an item in the store's inventory with the given itemCode.
-
Field Details
-
inventory
A data structure to keep track of the current inventory of the store, implemented using two data structures (HashMap and ArrayList) that we will study later in the semester. A HashMap stores entries as (key,value) pairs, where the key is used to store and quickly access the entries and the value is the actual data we wish to store. An ArrayList is a Java implementation of a list data type (that is, a collection that stores its data in a linear order) that behaves like a resizable array. Thus, for each item code (key), this inventory map stores a list (value) of all the items with that code currently in stock.
-
-
Constructor Details
-
Store
public Store()A basic constructor that initializes the inventory to be empty. This will be likely be useful for unit testing. -
Store
A constructor that initializes the inventory of the store based on the lines of a simulation file. Lines are read one at a time until reading the line "Coupons:" (which signifies the end of the inventory. Each inventory line in this file specifies a quantity of items of a certain type (name, code, and price) to be added to the inventory.
-
-
Method Details
-
shelve
Inserts this item into the store's inventory. -
hasInStock
public boolean hasInStock(long itemCode) Returns whether there is an item in the store's inventory with the given itemCode. -
unshelve
Removes and returns an item in the store's inventory with the given itemCode. There must be such an item in stock, which can be verified by calling hasInStock().
-