Learning Objective(s)
- Improve skills with methods
- Improve skills with files (and exceptions)
- Learn the need for arrays
Overview of the Program
Create a program that will allow the user to maintain a shopping list. The shopping list contains a list of items (in no particular order) and the number of each item to be purchased.
Specifics
- Use constants for each command, the data file, and a temporary file.
- Commands include:
- Display the entire list
- Display a specific item in the list
- Add an item to the list
- Change the amount needed of an item already in the list
- Delete an item in the list
- Exit
- Numbers are to be used to indicate which command to execute
- Problems with files are to be handled by catching the exception not throwing it
- If trying to display an item, delete an item, or change the amount needed of an item and the item is not in the list, an error message should be display
- If trying to change the amount of the item and the new amount is 0, an error message should be delayed because that item should be deleted instead
- Adapt the sequential search to return the amount associated with the item (and -1 if it is not in the list)
- If a method opens a file, it must also close that file.
- You CANNOT use arrays (or any similar data structure).
Sample dialogue
Below is a sample dialogue. The prompts may vary but the input given by the user is to be the same format. Your output can vary somewhat as long as the required data is nicely displayed.
0) Display the entire shopping list.
1) Display one item.
2) Add an item.
3) Change the number of an item.
4) Remove an item.
5) Exit the program.
Command? 0
Shopping list:
Amount Item
5 apple
2 ice cream
7 potato
2 orange
0) Display the entire shopping list.
1) Display one item.
2) Add an item.
3) Change the number of an item.
4) Remove an item.
5) Exit the program.
Command? 1
What item should be displayed? bread
bread is not on the shopping list.
0) Display the entire shopping list.
1) Display one item.
2) Add an item.
3) Change the number of an item.
4) Remove an item.
5) Exit the program.
Command? 1
What item should be displayed? apple
The need is for 5 apple
0) Display the entire shopping list.
1) Display one item.
2) Add an item.
3) Change the number of an item.
4) Remove an item.
5) Exit the program.
Command? 2
What item do you want to add? bread
How many of bread should be added to the list. 3
0) Display the entire shopping list.
1) Display one item.
2) Add an item.
3) Change the number of an item.
4) Remove an item.
5) Exit the program.
Command? 3
What item do you want to add? potato
How many to add (neg to remove some)? 3
0) Display the entire shopping list.
1) Display one item.
2) Add an item.
3) Change the number of an item.
4) Remove an item.
5) Exit the program.
Command? 0
Shopping list:
Amount Item
5 apple
2 ice cream
10 potato
2 orange
3 bread
0) Display the entire shopping list.
1) Display one item.
2) Add an item.
3) Change the number of an item.
4) Remove an item.
5) Exit the program.
Command? 4
What item do you want removed? orange
0) Display the entire shopping list.
1) Display one item.
2) Add an item.
3) Change the number of an item.
4) Remove an item.
5) Exit the program.
Command? 0
Shopping list:
Amount Item
5 apple
2 ice cream
10 potato
3 bread
0) Display the entire shopping list.
1) Display one item.
2) Add an item.
3) Change the number of an item.
4) Remove an item.
5) Exit the program.
Command? 5
You can also run a solution for this program if you want. See classroom instructions for more details.
Lab Hints
Submission
- Create a software development report
- For the system design, you may use my flowchart if it is the design of your program. Otherwise, you need to make your own.
- For testing report,
- The menu does not need to be included in the expected or actual results.
- make sure you do statement coverage testing
- For the improvement section, specify how many points were lost from the last lab that you should not lose points for on this lab because you corrected the problem
- If the solution is used, that should be included in "Outside Resources"
- create a pdf document from your software development report
- create an empty zip folder
- place only Shoppinglist.java and your pdf document into it
- submit the zip folder on canvas
Optional improvements
Optional improvements should ONLY be worked on once the program is completing working. In addition, the work is to be done on your own with little if any help for lab assistants or the instructor.
- Look at the solution to the previous lab. Compare your work to it and answer the following questions
- What was the same between the two?
- What did you do better than the solution?
- What did the solution do better than you?
- What insights have you learned by looking at the solution?
- Generate a pdf file (name "assessment.pdf") with your answers and add it to the zip folder
- Maintain the list sorted but do not use arrays or any library sort routines. Save the code as "ShoppingListExtra.java" and add it to the zip folder