0

I am having an issue in a while loop where I am trying to get user input for an item number and its price. The loop end statement has a user input section to return the value to see if it matches the loop statement so the user can input another item and its price. Although, when I run the program it gets to my last display and closes. I need to be able to input multiple item numbers and prices, or at the very least get it to actually loop and input that info.

I tried a few things and have had no luck. I tried creating another object to see if it was because there was no available space to store it. But then the set method is specific to inv1. Not sure if that is the hold up or what. Any input is appreciated.

The code is as follows:

import java.util.Scanner;
class UseInventory
{
  public static void main (String [] args)
  {

    String input = " ";
    String go = "y";
    String stop = "n";

    Inventory inv1 = new Inventory();
    Inventory inv2 = new Inventory();

    Scanner user = new Scanner(System.in);

    System.out.println("Do you have an item to enter? y or n");
    input = user.nextLine();

    while (input.equals(go))
    {
      System.out.println("Please enter the item number: ");

      inv1.setItemNumber(user.nextLine());

      System.out.println("Please enter the times original price: ");

      inv1.setOrigPrice(user.nextDouble());

      System.out.println("Do you have another item to enter? y or n");
      input = user.nextLine();
    }//end while

  }//end main

}//end class

0 Answers0