When submitting this lab, submit a .java file called ShoppingList2, and create the following structure in Eclipse: Package Name: week9 Class Name: ShoppingList2 For this lab you will be updating your...

1 answer below »








When submitting this lab, submit a .java file called ShoppingList2, and create the following structure in Eclipse:






    • Package Name:week9


    • Class Name:ShoppingList2




For this lab you will be updating your last program to make the shopping list more interesting.This is about string methods.Instead of simply entering items into a shopping list, your users will now add items and the corresponding amounts desired into the shopping list as a single string using the format ‘:’. Your program will need to split the string to get the proper formatting as described below and shown in the example run.String formatting must appear exactly as shown in the example run.


Make the following updates to your last program



addItems()



  • Require the user to use a ‘:’ when entering new items into the shopping list with the following format: :

  • BEFORE adding the user entry into your shoppingList ArrayList, do the following:

    • Check to be sure that each new item includes a ‘:’ If the item does not contain a ‘:’, display a helpful message indicating the required format as shown in the example run.

    • Remove any leading or trailing spaces before and after the AND before and after the . Do this before adding the item to the shopping list. Example: If the user enters the string ‘ apples : 6 ‘, then ‘apples:6’ should be added to the shopping list.






showItems()



  • Display your Shopping List to look like the following:



--------------------------




Shopping List



----------------------------



Apples 6



Oranges 10



--------------------------



  • To get your shopping list to display as shown above, you will need to:

    • Print the title for your Shopping List

    • Split each item into its itemName and itemAmount

    • Use System.out.printf() to print the itemName and itemAmount with width specified






deleteItems()



  • There are no changes to deleteItems().




sort_Items()



  • There are no changes to sortItems().




Hint:



  • When splitting a string into two substrings based on a given character delimiter, a combination ofindexOf()andsubstring()can be used.


Example:


To separate “Hello,World” into two strings, “Hello” and “World” do the following:



originalWord = “Hello,World”; //the original user input



commaIndex = originalWord.indexOf(“,”); //gets the index number for where the “,” is located



firstWord = originalWord.substring(0, commaIndex); //gets everything before the comma



secondWord = originalWord.substring(commaIndex + 1); //gets everything after the comma


Results:



  • firstWord now equals "Hello"

  • secondWord now equals "World"




Example Run













  • 1. Add Items


    2. Delete Items


    3. Show Items


    4. Sort Items


    5. Exit


    Please enter a command: 1



    Add an item to the list (or just hit 'ENTER' when done): Fruit


    Invalid Entry. No ':' found. Entry must be in the form ':'



    Add an item to the list (or just hit 'ENTER' when done): Oranges : 12


    'Oranges:12' has been added to the Shopping List.



    Add an item to the list (or just hit 'ENTER' when done): Breakfast Bars: 1


    'Breakfast Bars:1' has been added to the Shopping List.



    Add an item to the list (or just hit 'ENTER' when done): Eggs : 24


    'Eggs:24' has been added to the Shopping List.



    Add an item to the list (or just hit 'ENTER' when done): Apples:6


    'Apples:6' has been added to the Shopping List.



    Add an item to the list (or just hit 'ENTER' when done):


    4 items have been added to your Shopping List.



    1. Add Items


    2. Delete Items


    3. Show Items


    4. Sort Items


    5. Exit


    Please enter a command: 3



    ---------------------------



    Shopping List



    ---------------------------


    Oranges 12


    Breakfast Bars 1


    Eggs 24


    Apples 6


    ---------------------------



    1. Add Items


    2. Delete Items


    3. Show Items


    4. Sort Items


    5. Exit


    Please enter a command: 4


    The Shopping List has been sorted.



    ---------------------------



    Shopping List



    ---------------------------


    Apples 6


    Breakfast Bars 1


    Eggs 24


    Oranges 12


    ---------------------------



    1. Add Items


    2. Delete Items


    3. Show Items


    4. Sort Items


    5. Exit


    Please enter a command: 5










Grading









This assignment isworth20 points and will be graded according to the following rubric:




Rubric

9.5 Individual Lab Rubric.9.5 Individual Lab Rubric.






















CriteriaRatingsPts
This criterion is linked to a Learning OutcomeStudent output looks like the Example Run.10pts

This criterion is linked to a Learning OutcomeStudent accurately uses indexOf(), substring(), and trim().10pts

Total Points:20

9.4 Lab - Shopping List - Part 1 - Multi-Function Shopping List (1.5h)" style="float: left;">Previous
9.6 Paired Lab - getValidX () with ranges (1h)" style="float: right;">Next

Answered Same DayJun 18, 2021

Answer To: When submitting this lab, submit a .java file called ShoppingList2, and create the following...

Kshitij answered on Jun 18 2021
147 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here