Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help doing this assignment, instructions for assignment is in the photos below. - Please identify which version you decided to follow, minimum, standard, or

Need help doing this assignment, instructions for assignment is in the photos below.

- Please identify which version you decided to follow, minimum, standard, or challenge.

- Please only use the java programming language.

- Please follow instructions thoroughly for a thumbs up. Much appreciated!

Starting code for ShoppingList.java:

public class ShoppingList { private java.util.Scanner scan; // declare storage for the list items public ShoppingList() { scan = new java.util.Scanner(System.in); // initialize storage for list items } public void printList() { System.out.println("Your shopping list:"); // print the list } public void addToList(String item) { // add item to the list } public void emptyList() { // empty the list } public String getInput() { System.out.print("Enter your item or command: "); return scan.next().trim(); } public void printWelcome() { System.out.println("Welcome to the XYZ Shopping List Program."); } public void printThankYou() { System.out.println("Thank you for using the XYZ Shopping List Program."); } public void printHelp() { System.out.println("Here are the list of commands:"); System.out.println(" -p : Print the list"); System.out.println(" -e : Empty the list"); // System.out.println(" -r n : Remove the nth item from the list"); // System.out.println(" -r Xxx : Remove item Xxx from the list"); System.out.println(" -x : Exit the application"); System.out.println(" -h : Print this command list"); } public void go() { String input; printWelcome(); printHelp(); input = getInput(); while( ! input.equals("-x")) { switch(input) { case "-h": printHelp(); break; case "-p": printList(); break; case "-x": break; case "-e": emptyList(); break; default: addToList(input); } input = getInput(); } printThankYou(); } public static void main(String[] args) { ShoppingList list; list = new ShoppingList(); list.go(); } }

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Homework Assignment: Shopping List - LL Objectives Use a linked list to implement a simple shopping list. Minimal Version Download the starting point for this assignment: ShoppingList.java. Read through this code. If there are things that you don't understand, you can ask about them in the discussion forum. Alternately, you can look in the documentation and then make a post about what had confused you and what you found. This is a simple shopping list application. This application will allow the user to add items to a shopping list, review the contents of the list, and remove all items from the list. This shopping list will not persist between runs of the application. The current implementation in incomplete. It does not include any mechanism to store the shopping list items. Your task for this assignment is to implement storage for this application using a linked list. A sample run of this program is shown below. (User input is shown in bold.) Welcome to the XYZ Shopping List Program. Here are the list of commands: -p: Print the List -e : Empty the List -X: Exit -h: Print this command list Enter your item or command: pizza Enter your item or command: milk Enter your item or command: bread Enter your item or command:-p Your shopping list: pizza * * milk * bread Enter your item or command: -h Here are the list of commands: -p: Print the List Emntutbalist -p: Print the List -e : Empty the List -X: Exit -h: Print this command list Enter your item or command: -e All items removed from list. Enter your item or command: apples Enter your item or command:-p Your shopping list: * apples Enter your item or command: -X Thank you for using the XYZ Shopping List Program. Entries that are not recognized as commands are understood to be new items to be added to the list. Implement a simple list using a linked list Modify the ShoppingList class to use a linked list. You will need to declare a field (member variable) of linked list type. The linked list will store the values, the entries in the shopping list, in its nodes. The linked list will also store the size of the linked list itself, which corresponds to the items in the shopping list. In the rest of this write-up, we will refer to this integer as "the size". In the constructor, instantiate the linked list (head). Needless to say, you need to update methods of ShoppingList to use the linked list. To help you test your work, you will need to be able to add a couple of items to the shopping list "manually". This will allow you to test the printList and emptyList methods before you need to implement the addToList. You need to set the the contents of the list. So, if your linked list is named linked List, this set-up code would look like the following: private void testList() { linked List.add("pizza"); linkedList.add("milk"); linked List.add("bread"); } Start by completing the printList method. Notice that the method already prints out a "header line". Following this, the method should print out the items in the list, one per line, prefixed with "space-space-star-space". If the list is empty, print the textual message: "No items in list." You can test your implementation by modifying main as follow: You can test your implementation by modifying main as follow: public static void main(String[] args) { ShoppingList list; list = new ShoppingList(); list.printList(); list.testList(); list.printList(); } This should generate: Your shopping list: * No items on list. Your shopping list: * pizza * milk * bread Your shopping list: * No items on list. Finally, implement addToList. Since this completes the implementation. You can test the application by restoring main to call the driver function go.: This is called a "driver" function because it manages (drives) the application. public static void main(String[] args) { ShoppingList list; list = new ShoppingList(); list.go(); } General Notes This assignment focuses on using your own implementation of the linked list. Do not use any methods from the java.util.LinkedList class. The java.util.Scanner class should only be instantiated once, in the constructor. General Notes This assignment focuses on using your own implementation of the linked list. Do not use any methods from the java.util.LinkedList class. The java.util.Scanner class should only be instantiated once, in the constructor. Standard Version This application should be designed to be user-tolerant. That is, user input errors need to be handled. For the Standard Version, you need to enhance the shopping list application to make it more robust. Currently, there are several kinds of errors that the application does not handle: Duplicate items Numbered list Constructor instantiation . No Duplicates Create a method that will search the list for a given value. This method can return a Boolean value (Java type boolean). Update the No Duplicates Create a method that will search the list for a given value. This method can return a Boolean value (Java type boolean). Update the driver method to check for duplicates before adding an item to the list. If the new item already exists in the list, report the duplicate and do not add it to the list. In the duplicate report, echo the duplicate item. If it does not exist in the list, add it. Enter your item or command: apple Enter your item or command: apple Duplicate item apple not added to list. Numbered List Update the printList method to create a number list rather than a bulleted list. Notice this list is numbered the way people number lists, not the way computers do. (That is, it starts at one, rather than zero.) Your shopping list: 1. pizza 2. milk 3. bread Constructor Instantiation You have two fields in the ShoppingList class: a java.util.Scanner, and a linked list. The Scanner and linked list must be instantiated to be useful. The instantiation for these fields shall occur only within the constructor, no where else in the code. Alternately stated, no Scanner or linked list instances shall be created outside of the constructor. Challenge version For the Challenge option, implement the following enhancements: Single item removal Remove a single item Add a command to the menu that removes a single item from the list. There are two forms that this command could take. You may implement either form of single-item removal. Implementing both will count toward additional Challenge points. Form One In this case, the command shall be -r n, where n is the number of the item to be removed from the list. Enter your item or command:-p Enter your item or command:-p Your shopping list: 1. pizza 2. milk 3. bread Enter your item or command: -r 1 Enter your item or command:-p Your shopping list: 1. milk 2. bread Form Two Alternately, the command shall be -r x, where x is the value (String) for the item to be removed from the list. Enter your item or command:-p Your shopping list: 1. milk 2. pizza 3. milk 4. bread 4. bread 5. milk Enter your item or command: -r milk Enter your item or command:-p Your shopping list: 1. pizza 2. bread Notice that the String version will remove all matching occurrences of the value, if they exist. Create a method (or two) that will remove a single item from the list. For Form One, the method will take an int as its parameter, the index value of the item to be removed. For Form Two, the method will take a String as its parameter, the value of the item(s) to be removed. Any items in the list following the one removed will need to up "slide up" within the list to close the empty place. Note: It is possible that a shopping list may contains String values representing integers; for example: "3". In this case: the command -r 3 would be ambiguous. If you implement both remove options, check first for a string match, then for an index value. If the item for removal does not exist, report the error. For example, Enter your item or command: -r 15 liat Enter your item or command: -r 15 * No item 15 in shopping list Note: This command consists of two tokens. For Form One, the numerical value will need to be verified to be an integer. It will need to be checked to insure that it is in the correct range of values. If the additional token does not pass input validation, print out an error message and leave the list unchanged. Also note, as shown in the Standard option, the user list starts at one (1), not zero (O). Update the list of commands in printHelp to reflect the added command(s). You may want to add some spaces after the colon in the menu items so that the colons continue to align vertically. Report One of the ways to improve is to reflect on past performance. Write a report that answers the following questions: . how did you go about starting this project? what works and what doesn't? what design decisions did you make? did these test cases help you verify the correctness of your results? the surprises or problems you encountered while implementing this application the most important thing(s) you learned from this assignment . the most important thing(s) you learned from this assignment what you would do differently next time? . Submission Multiple files: . All Java source code file ASCII report file Grading Rubric 15 points for the Standard Version: Functionality: 12 points 9/ Minimal Version (correctly handles the list) 12/ Minimal + Standard Version (plus, check for duplicate items; numbered list) 13/ Minimal, Standard, and Challenge Version (plus, delete single item) 147 Challenge Version (with both delete implementations) Documentation: 2 points Homework Assignment: Shopping List - LL Objectives Use a linked list to implement a simple shopping list. Minimal Version Download the starting point for this assignment: ShoppingList.java. Read through this code. If there are things that you don't understand, you can ask about them in the discussion forum. Alternately, you can look in the documentation and then make a post about what had confused you and what you found. This is a simple shopping list application. This application will allow the user to add items to a shopping list, review the contents of the list, and remove all items from the list. This shopping list will not persist between runs of the application. The current implementation in incomplete. It does not include any mechanism to store the shopping list items. Your task for this assignment is to implement storage for this application using a linked list. A sample run of this program is shown below. (User input is shown in bold.) Welcome to the XYZ Shopping List Program. Here are the list of commands: -p: Print the List -e : Empty the List -X: Exit -h: Print this command list Enter your item or command: pizza Enter your item or command: milk Enter your item or command: bread Enter your item or command:-p Your shopping list: pizza * * milk * bread Enter your item or command: -h Here are the list of commands: -p: Print the List Emntutbalist -p: Print the List -e : Empty the List -X: Exit -h: Print this command list Enter your item or command: -e All items removed from list. Enter your item or command: apples Enter your item or command:-p Your shopping list: * apples Enter your item or command: -X Thank you for using the XYZ Shopping List Program. Entries that are not recognized as commands are understood to be new items to be added to the list. Implement a simple list using a linked list Modify the ShoppingList class to use a linked list. You will need to declare a field (member variable) of linked list type. The linked list will store the values, the entries in the shopping list, in its nodes. The linked list will also store the size of the linked list itself, which corresponds to the items in the shopping list. In the rest of this write-up, we will refer to this integer as "the size". In the constructor, instantiate the linked list (head). Needless to say, you need to update methods of ShoppingList to use the linked list. To help you test your work, you will need to be able to add a couple of items to the shopping list "manually". This will allow you to test the printList and emptyList methods before you need to implement the addToList. You need to set the the contents of the list. So, if your linked list is named linked List, this set-up code would look like the following: private void testList() { linked List.add("pizza"); linkedList.add("milk"); linked List.add("bread"); } Start by completing the printList method. Notice that the method already prints out a "header line". Following this, the method should print out the items in the list, one per line, prefixed with "space-space-star-space". If the list is empty, print the textual message: "No items in list." You can test your implementation by modifying main as follow: You can test your implementation by modifying main as follow: public static void main(String[] args) { ShoppingList list; list = new ShoppingList(); list.printList(); list.testList(); list.printList(); } This should generate: Your shopping list: * No items on list. Your shopping list: * pizza * milk * bread Your shopping list: * No items on list. Finally, implement addToList. Since this completes the implementation. You can test the application by restoring main to call the driver function go.: This is called a "driver" function because it manages (drives) the application. public static void main(String[] args) { ShoppingList list; list = new ShoppingList(); list.go(); } General Notes This assignment focuses on using your own implementation of the linked list. Do not use any methods from the java.util.LinkedList class. The java.util.Scanner class should only be instantiated once, in the constructor. General Notes This assignment focuses on using your own implementation of the linked list. Do not use any methods from the java.util.LinkedList class. The java.util.Scanner class should only be instantiated once, in the constructor. Standard Version This application should be designed to be user-tolerant. That is, user input errors need to be handled. For the Standard Version, you need to enhance the shopping list application to make it more robust. Currently, there are several kinds of errors that the application does not handle: Duplicate items Numbered list Constructor instantiation . No Duplicates Create a method that will search the list for a given value. This method can return a Boolean value (Java type boolean). Update the No Duplicates Create a method that will search the list for a given value. This method can return a Boolean value (Java type boolean). Update the driver method to check for duplicates before adding an item to the list. If the new item already exists in the list, report the duplicate and do not add it to the list. In the duplicate report, echo the duplicate item. If it does not exist in the list, add it. Enter your item or command: apple Enter your item or command: apple Duplicate item apple not added to list. Numbered List Update the printList method to create a number list rather than a bulleted list. Notice this list is numbered the way people number lists, not the way computers do. (That is, it starts at one, rather than zero.) Your shopping list: 1. pizza 2. milk 3. bread Constructor Instantiation You have two fields in the ShoppingList class: a java.util.Scanner, and a linked list. The Scanner and linked list must be instantiated to be useful. The instantiation for these fields shall occur only within the constructor, no where else in the code. Alternately stated, no Scanner or linked list instances shall be created outside of the constructor. Challenge version For the Challenge option, implement the following enhancements: Single item removal Remove a single item Add a command to the menu that removes a single item from the list. There are two forms that this command could take. You may implement either form of single-item removal. Implementing both will count toward additional Challenge points. Form One In this case, the command shall be -r n, where n is the number of the item to be removed from the list. Enter your item or command:-p Enter your item or command:-p Your shopping list: 1. pizza 2. milk 3. bread Enter your item or command: -r 1 Enter your item or command:-p Your shopping list: 1. milk 2. bread Form Two Alternately, the command shall be -r x, where x is the value (String) for the item to be removed from the list. Enter your item or command:-p Your shopping list: 1. milk 2. pizza 3. milk 4. bread 4. bread 5. milk Enter your item or command: -r milk Enter your item or command:-p Your shopping list: 1. pizza 2. bread Notice that the String version will remove all matching occurrences of the value, if they exist. Create a method (or two) that will remove a single item from the list. For Form One, the method will take an int as its parameter, the index value of the item to be removed. For Form Two, the method will take a String as its parameter, the value of the item(s) to be removed. Any items in the list following the one removed will need to up "slide up" within the list to close the empty place. Note: It is possible that a shopping list may contains String values representing integers; for example: "3". In this case: the command -r 3 would be ambiguous. If you implement both remove options, check first for a string match, then for an index value. If the item for removal does not exist, report the error. For example, Enter your item or command: -r 15 liat Enter your item or command: -r 15 * No item 15 in shopping list Note: This command consists of two tokens. For Form One, the numerical value will need to be verified to be an integer. It will need to be checked to insure that it is in the correct range of values. If the additional token does not pass input validation, print out an error message and leave the list unchanged. Also note, as shown in the Standard option, the user list starts at one (1), not zero (O). Update the list of commands in printHelp to reflect the added command(s). You may want to add some spaces after the colon in the menu items so that the colons continue to align vertically. Report One of the ways to improve is to reflect on past performance. Write a report that answers the following questions: . how did you go about starting this project? what works and what doesn't? what design decisions did you make? did these test cases help you verify the correctness of your results? the surprises or problems you encountered while implementing this application the most important thing(s) you learned from this assignment . the most important thing(s) you learned from this assignment what you would do differently next time? . Submission Multiple files: . All Java source code file ASCII report file Grading Rubric 15 points for the Standard Version: Functionality: 12 points 9/ Minimal Version (correctly handles the list) 12/ Minimal + Standard Version (plus, check for duplicate items; numbered list) 13/ Minimal, Standard, and Challenge Version (plus, delete single item) 147 Challenge Version (with both delete implementations) Documentation: 2 points

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Assess three steps in the selection process.

Answered: 1 week ago

Question

Identify the steps in job analysis.

Answered: 1 week ago