Как правильно получить доступ к индексу/идентификатору элемента? Поскольку я поставил 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
Доступ к индексу по идентификатору. ЯВА ⇐ JAVA
Программисты JAVA общаются здесь
1763633832
Anonymous
Как правильно получить доступ к индексу/идентификатору элемента? Поскольку я поставил 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");
Подробнее здесь: [url]https://stackoverflow.com/questions/79825375/acessing-index-by-id-java[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия