我正在尝试在while循环中运行验证,以确保尚未使用ID,但是程序会不断跳过我的验证-有关如何使验证生效的任何建议?
public void addinventory items(ArrayList<Inventory> mv) {
Scanner scan = new Scanner(System.in);
System.out.println("Choose one of the following menu options (1,2,or 3):
\n1. Update an item in the inventory");
System.out.println("2. Add a new inventory item");
System.out.println("3. Exit to main menu\n");
int choice = scan.nextInt();
while (choice == 2) {
System.out.println("What is the ID of the inventory item?");
String inventoryID = scan.nextLine();
while (checkId(mv, inventoryID)) {
System.out.println("This ID already exists, enter a different ID: ");
inventoryID = scan.nextLine();
}
System.out.println("How many inventory items do you wish to add?");
int numinventory items = scan.nextInt();
scan.nextLine();
System.out.println("What is the description?");
String desc = scan.nextLine();
System.out.println("How many stocks to did you purchase?");
int num = scan.nextInt();
System.out.println("What is the cost of the inventory item?");
double cost = scan.nextDouble();
System.out.println("What is the value of the inventory item?");
double value = scan.nextDouble();
Inventory inventory = new Inventory(inventoryID.toUpperCase(), desc, num, cost,
value);
mv.add(inventory);
numinventory items--;
}