Question: create a java program that does the following: 1.that asks user to input items (string) they would like to keep in their bag 2. a

create a java program that does the following:

1.that asks user to input items (string) they would like to keep in their bag

2. a separate search function not in main that allows user to search for string

3.Dont use static inventory

4. ask user how many items they want to add

Add code to following underneath

import java.util.ArrayList;

import java.util.Scanner;

public class Inventory {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println("How many items to add:");

int a = sc.nextInt();

ArrayList Items = new ArrayList(a);

for(int i=0; i

{

System.out.printf("Enter %dth Item: ", i+1);

String s = sc.next();

Items.add(s);

}

for(int i=0; i

{

System.out.println(Items.get(i));

}

System.out.println("Name of Item to search: ");

String str = sc.next();

if(Items.contains(str)){

System.out.println(str);

}

else{

System.out.println("no match");

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!