Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need java help and can't seem to find any straightforward answers online. I am creating a menu with different methods and different tasks. One

I need java help and can't seem to find any straightforward answers online.

I am creating a menu with different methods and different tasks. One of the tasks is use a method and add a product (one if else statement) and view products (another if else statement) I am using the same variable for both, trying to receive the input and have it written back into the output of the console, but it just says "null". Below is the pasted portion of my code in which I am having trouble with. Choice 2 is what I am having trouble with as the "product[i]" isn't working there. If you see anything wrong with it please help!!!

String[] product = new String [20]; // products // establishing variables int choice; int i = 0; // creating while loop while(true) { // invalid choice System.out.print("Enter your choice: "); choice = input.nextInt(); if(choice<1 || choice>2){ System.out.println("Invalid choice."); } // choice 1 if(choice ==1){ System.out.print("Please enter product name:"); product[i] = input.next(); // adding product System.out.println(" Added Successfully:" + (product[i])); break; } else if // choice 2 (choice ==2){ // viewing inventory System.out.println(" Inventory Products"); System.out.println(product[i]); break; }} }

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

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions

Question

4. What are the current trends in computer software platforms?

Answered: 1 week ago