CSCI 1110 Assignment 4 Store Simulation
Note that for this assignment you will just create these features and test them; you will not add these new features to the simulator code used in assignment 3.
Part 1: Shopping Cart and ItemCreate a simple Item class that represents an item that can be purchased. It should have the following public methods:
public Item (String sku)
A constructor with a single parameter representing the SKU1 for the item.
public String getSKU ()
Returns the SKU
Create a ShoppingCart class that represents a customer’s shopping cart. It should have the following public methods:
public ShoppingCart (int maxItems)
A constructor with a single parameter representing the maximum number of items the shopping cart can hold.
public boolean addItem (Item item)
Adds an item to the shopping cart if not full. Returns true if the add was successful, false otherwise.
public List<Item> getItems ()
Retrieves a list of all items in the ShoppingCart, but doesn’t remove the items from the cart.
public int getItemCount ()
Returns the number of items in the ShoppingCart.
public boolean isFull ()
Indicates whether the ShoppingCart is full.
public Item removeItem ()
Removes an Item from the ShoppingCart. Note that there is (at present) no way to remove a specific item (e.g. by SKU); this method removes an Item in an unspecified order.
Part 2: ProductInfo and ItemScannerCreate a ProductInfo class that represents information about a specific product. It has the following public methods:
public ProductInfo (String sku, String desc, double unitPrice)
A constructor with three parameters: sku, representing the SKU for the product, desc, a product description, and unitPrice, the price for a single Item of this product type.
public String getSKU ()
Returns the SKU
public String getDescription ()
Returns the product description
public void setDescription (String description)
Updates the product description
public double getUnitPrice ()
Returns the unit price for the product
public void setUnitPrice (double price)
Updates the unit price for the product
public String toString ()
A method returning a String representation of the ProductInfo as “[Description], SKU [SKU], $ [UnitPrice]” where the unit price is formatted to two decimal places, as illustrated here:
Bic Pen (Black), SKU AB2343, $0.99
Create an ItemScanner class that returns the ProductInfo corresponding to an Item. It does this by mapping SKUs to ProductInfo objects in a Map data structure.
It has the following public methods:
public ItemScanner ()
A constructor taking no parameters.
public boolean addProductInfo (ProductInfo pInfo)
Adds ProductInfo to the ItemScanner’s bank of product information. Returns true if added successfully, false if it has already been added.
public ProductInfo getProductInfo (String sku)
Returns the ProductInfo corresponding to the SKU, or null if there is no corresponding ProductInfo for the SKU.
Part 3: ShoppingCartTestCreate a test class called ShoppingCartTest with a main routine that does the following:
- Initializes 4 ProductInfo objects with different SKUs and Descriptions (and possibly different Unit Prices), and adds them to an ItemScanner object.
- Initializes 10 Items, each with a SKU value that matches the SKU of a ProductInfo object
- Creates a ShoppingCart and adds all 10 items to it
- Calls a static method called “simulateCheckout”, as defined below
public static void simulateCheckout (ShoppingCart cart, ItemScanner scanner)
- Removes each Item from the ShoppingCart one by one, printing information about each Item as it is removed, and keeping a tally of the total cost for all items
- Prints the number of items purchased and the total cost (formatted to 2 decimal places).
- See the sample output below:
Item 1: Bic Pen (Black), SKU AB2343, $0.99
Item 2: Bic Pen (Blue), SKU AB2342, $0.99
Item 3: Bic Pen (Black), SKU AB2343, $0.99
Item 10: Bic Pen (Sparkles), SKU AB2428, $2.99
10 items purchased, total $11.90
GradingYour code must compile to receive marks!
You must use Javadoc headers on public and protected classes, methods and instance variables.
Remember to give meaningful variable names.
Each problem on the assignment will be graded based on three criteria:
1. Functionality: “Does it work according to specifications?". This is determined by running your program through a number of test configurations and ensuring that the behaviour matches the expected behaviour.
2. Quality of Solution: "Is it a good solution?" This considers whether the solution is correct, efficient, covers boundary conditions, does not have any obvious bugs, etc. This is determined by visual inspection of the code. Initially full marks are given to each solution and marks are deducted based on faults found in the solution.
3. Code Clarity: "Is it well written?" This considers whether the solution is properly structured, isn’t unnecessarily complex, uses good variable, class, and method names, and is well-documented. A single code clarity score is assigned for all solutions.
You are expanding the Store Simulator to have Shopping Carts and Item Scanning functionality