Lab 1: Shopping Cart Data Structure
Due Date and Submission Requirements
- Due Date: Friday, January 24th at 11:59 p.m.
- Partner Information: This is an individual assignment. You are allowed to collaborate with other students, but each student must submit their individual, independent solution.
- Submission Instructions: Upload your solution (ShoppingCartArray.java and ShoppingCartLinkedList.java), to the BrightSpace(D2L) Lab 1 Dropbox.
The goal of this lab is:
- Gain experience using the Array and LinkedList data structures
Directions
Using the code we've been working with this week (you should download a fresh set of files below). Do not change any code other than adding the body of the four methods described below (and the demo class for additional testing). You do not need to add any more instance fields or methods.
Fill in the body of the searchForItem(String name) method for the ShoppingCartArray and ShoppingCartLinkedList classes.
This method takes in an item name to search for in the shopping cart. If the item is found, the item is printed out. If the item is not in the shopping cart, then "[item_name] is not in the shopping cart" should be printed out.
Next, you will need to fill in the body of the removeItem(String name) method for the ShoppingCartArray and ShoppingCartLinkedList classes. This method takes in an item name to be removed from the data structure.
Actually remove the entry, don’t just set it to null: In the array implementation, the array needs to shrink
in size by 1 and in the linked list implementation, the Item object needs to be removed from the list (you
can just use a method from the Linked List documentation). You can assume the item they are trying to remove exists somewhere in the data structure (ie they will never try to remove an item that does not exist). Additionally, there is no need to handle duplicate names.
That is four methods in total. You are welcome to change the demo class to test your code.
Required Output
When you run your program, it should look exactly like output seen in in this screenshot .
Starting Code
Assumptions
There won't be duplicate item names in the data structure
Users wont try to remove an item that does not exist
If you are removing an item with a quantity greater than one, it should still remove the entire item (not decrease the quantity by one)
Grading (10 points)
- 2 points - searchForItem() is correct for array
- 2 points - searchForItem() is correct for LL
- 3 points - removeItem() is correct for array
- 3 points - removeItem() is correct for LL
Grading deductions
If your code does not compile, you will receive an automatic zero