Posted: Saturday, April 4
Due: Monday, April 13
70 points (+ up to 15 extra credit)
This assignment will give you more practice with implementing your own classes and managing collections using arrays. You'll build a shopping list program with items and estimated prices.
Implement a class GroceryItem that stores data about an item on your shopping list. It should include the following private fields:
Your class should provide the following public methods:
Implement a class GroceryList to manage a collection of GroceryItem objects.
It should contain the following private fields:
Public methods must include:
// Example usage
GroceryList groceries = new GroceryList();
groceries.addItem(new GroceryItem("Apples", 6, 0.29));
groceries.addItem(new GroceryItem("Milk", 2, 3.49));
System.out.println(groceries);
System.out.println("Total estimated cost: $" + groceries.totalEstimatedCost());
Write a very short driver program to test your code to make sure it's working. You are not required to write JUnit tests.
One of the purposes of this assignment is give you practice managing fixed-sized arrays. Although you may use the Arrays class, please refrain from using ArrayList or any other class in Java's Collections Framework. (We'll get to these soon 🤞.)
Suppose that we have a GroceryList with a capacity of 10 items and contains 4. We can visualize it this way (X represents a null reference):
Suppose that we then purchase item 1 (so it should be removed from the list). Each subsequent item is shifted down one position and a null reference is pulled in from the end.
One common point of confusion is how to count things in the collection.
Upload your .java files to Canvas.
It's a good idea to confirm through the Canvas submission page that what you've intended to submit was uploaded. We will grade what you submit. If you submit a corrupted, empty, or otherwise incorrect file, this is what we'll grade. It is your responsibility to verify through the Canvas submission page that you've submitted the correct files and that they were uploaded properly.
If you're unsure about how to submit, please consult Canvas' tutorial or see us for help.