Как правильно получить доступ к индексу/идентификатору элемента? Поскольку я поставил 101, и он переходит к 102, затем я это исправил, я поставил -1 на сканер, затем, когда я поставил 101, он получил доступ к 100.
Пожалуйста, помогите
System.out.println("============= INVENTORY ITEM LIST'S =============");
inventoryManager.DisplayItems();
if (inventoryManager.isEmpty()) {
System.out.println("Inventory is EMPTY no ITEM to EDIT");
// return if the inventory are empty
return;
}
// if not it bypasses the if statement and go direct into the userInput
System.out.println("Enter Item ID to edit");
int itemId = sc.nextInt() - 1;
String itemName = inventoryManager.getItemName(itemId);
if (itemName == null || itemName.isEmpty()) {
System.out.println("Error: the entered Item ID was ot found or is invalid");
return;
}
System.out.println("Enter the new PRICE of the ITEM");
double proposedPrice = sc.nextDouble();
sc.nextLine();
System.out.println("Enter the reason of Change");
String reason = sc.nextLine();
Request request = new Request(itemName, proposedPrice, reason);
staffRequestManager.submitRequest(request);
System.out.println("Submitting request");
Подробнее здесь: https://stackoverflow.com/questions/798 ... by-id-java