Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment 4: Shopping list (JAVA) Objective: Read in the names of several grocery items from the keyboard and create a shopping list using the Java

Assignment 4: Shopping list (JAVA)

Objective: Read in the names of several grocery items from the keyboard and create a shopping list using the Java ArrayList abstract data type.

1) Create a new empty ArrayList

2) Ask the user for 5 items to add to a shopping list and add them to the ArrayList (get from user via the keyboard).

3) Prompt the user for an item to search for on the list. Output a message to the user letting them know whether the item exists in the shopping list. Use a method that is part of the ArrayList class to do the search.

4) Prompt the user for an item to delete from the shopping list and remove it. (be sure to handle the case where they dont want to delete anything). Use a method that is part of the ArrayList class to do the delete.

5) Prompt the user for an item to insert into the list. Ask them what they want to insert and where they want to insert it (after which item). Use a method that is part of the ArrayList class to do the insertion.

6) Output the final list to the user.

My Code:

package assignment4;

import java.util.ArrayList;

import javax.swing.JOptionPane;

public class arrayexample {

public static void main(String[] args) { ArrayList shoppingList = new ArrayList(); int numItems = 5; for (int i = 1; i < numItems; i++) { String input = JOptionPane.showInputDialog("enter five Items. "); shoppingList.add(input); } String searchItems = JOptionPane.showInputDialog("Enter the item. "); boolean Items = shoppingList.contains(searchItems);

if(Items) { System.out.print("List contains item. "); } else { System.out.println("List does not contain item. "); } String removeItems = JOptionPane.showInputDialog("Which item do you want to remove? "); if(shoppingList.contains(removeItems)) { shoppingList.remove(removeItems); } else { System.out.println("The item does not contain in the list. "); } String addItem = JOptionPane.showInputDialog("What item do you want to add on the list "); String afterItem = JOptionPane.showInputDialog("What item do you want to add it after ");

}

}

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

Recommended Textbook for

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 1 Lncs 13426

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124227, 978-3031124228

Students also viewed these Databases questions

Question

Does it avoid using personal pronouns (such as I and me)?

Answered: 1 week ago

Question

Does it clearly identify what you have done and accomplished?

Answered: 1 week ago