Tags:
tag this topic
create new tag
view all tags
---+ More methods: Shopping lists: Fall 2024 ---++ 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 <font color="red"><b>CANNOT</b> <font color="black">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.<br /> <pre>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? <b><font color='blue'>0</font></b> 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? <b><font color='blue'>1</font></b> What item should be displayed? <b><font color='blue'>bread</font></b> 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? <b><font color='blue'>1</font></b> What item should be displayed? <b><font color='blue'>apple</font></b> 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? <b><font color='blue'>2</font></b> What item do you want to add? <b><font color='blue'>bread</font></b> How many of bread should be added to the list. <b><font color='blue'>3</font></b> 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? <b><font color='blue'>3</font></b> What item do you want to add? <b><font color='blue'>potato</font></b> How many to add (neg to remove some)? <b><font color='blue'>3</font></b> 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? <b><font color='blue'>0</font></b> 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? <b><font color='blue'>4</font></b> What item do you want removed? <b><font color='blue'>orange</font></b> 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? <b><font color='blue'>0</font></b> 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? <b><font color='blue'>5</font></b> </pre> You can also run a solution for this program if you want. See classroom instructions for more details. ---++ Lab Hints * Hint 1: [[%ATTACHURL%/ShoppingListFC.pdf][a flowchart that you can use]]: This flowchart is a bit more abstract and only partially complete on purpose. Your programming should be advancing. * Hint 2: [[CSC121F2024Lab08Hint2][Working with files]] * Hint 3: [[CSC121F2024Lab08Hint3][Problems with reading strings (esp. leading spaces and end of lines)]] ---++ 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. 1 Look at the solution to the previous lab. Compare your work to it and answer the following questions a. What was the same between the two? a. What did you do better than the solution? a. What did the solution do better than you? a. What insights have you learned by looking at the solution? a. Generate a pdf file (name "assessment.pdf") with your answers and add it to the zip folder 1 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
E
dit
|
A
ttach
|
Watch
|
P
rint version
|
H
istory
: r2
<
r1
|
B
acklinks
|
V
iew topic
|
Ra
w
edit
|
M
ore topic actions
Topic revision: r2 - 2024-10-21
-
CathyBareiss
Home
Site map
Assessment web
BethelAIResources2026 web
CenterForComputing web
ChatGPT web
Intro2AIatBethel web
Main web
Sandbox web
TWiki web
CenterForComputing Web
Create New Topic
Index
Search
Changes
Notifications
RSS Feed
Statistics
Preferences
P
P
P
View
Raw View
Print version
Find backlinks
History
More topic actions
Edit
Raw edit
Attach file or image
Edit topic preference settings
Set new parent
More topic actions
Account
Log In
Register User
E
dit
A
ttach
Copyright © 2008-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback