Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify Java code below ???? rules: - program starts with asking the user how many items they want to add - user will be asked

Modify Java code below ????

rules:

- program starts with asking the user how many items they want to add

- user will be asked to enter in the items to fill the slots

-use functions, all should not be located in main

-let user keep searching using loop and terminate when user wants

-take the search for items in array out of main and create a separate function for it so a user can search items

6.search function return following to user:

item name if its found

no match if not located

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 < a; i++) {

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

String s = sc.next();

Items.add(s);

}

for (int i = 0; i < Items.size(); i++)

{

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

}

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

String str = sc.next();

// calling isExist by passing the string and list

if(isExist(str, Items)){

System.out.println(str+" Found");

}

else{

System.out.println(str+" Not Found");

}

sc.close();

}

// method which is used to find the string in the arraylist

public static boolean isExist(String str,ArrayListitems){

return items.contains(str);

}

}

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

Main Memory Database Systems

Authors: Frans Faerber, Alfons Kemper, Per-Åke Alfons

1st Edition

1680833243, 978-1680833249

More Books

Students also viewed these Databases questions

Question

13-4 What is deethnicization? Give an example.

Answered: 1 week ago

Question

The issue of staff sensitivity to feedback

Answered: 1 week ago