Not sure what I have wrong here, tried several attemps to change things but still does the same thing. The below code is supposed to let the user enter in an item name to search for, when found will ask for a new quantity to be stored into a variable and placed into the inventory item to update the quantity of it. It does this no problem the first time, however when i want to do it again matchedName seems to be always false and skips over the loop. Any help appreciated, thanks. Also I tried to declare matchedName as a global variable at the top of my class and set it's value to true.. but have tried without this and makes no difference.
Code:System.out.println("Enter inventory NAME to update Quantity for: "); String testName; testName = in.nextLine(); boolean matchedName = false; testInventory.gotoBeginning(); // goes to beginning of the list - cursor points to first element in list do { inventory = (Inventory)testInventory.getCursor(); // gets the inventory object marked by the cursor if(inventory.getName().equalsIgnoreCase(testName)) { System.out.println("Enter new item Quantity: "); int newQuantity = in.nextInt(); inventory.setQuantity(newQuantity); matchedName = true; System.out.println("Item Quantity updated"); } }while (testInventory.gotoNext()); if (!matchedName) { System.out.println("Inventory Name not found - Quantity not updated!"); } break;




Reply With Quote