Hi guys,
I'm working on a console based application and I'm struck in a control flow issue for driver class. Any assistance is appreciated.
This method from the driver class call method from inventory class to search for a item that is stored in an arraylist. On query it return an arraylist of matching items if any match is found. The returned arraylist need to be numbered, formatted and presented to the user.
user select the item and the method call a method from shoppingcart class that add it to it to its arraylist. I have already completed all necessary methods for inventory and shoppingcart class.
DRIVER CLASS
private void addItemShoppingCart(){
CREATE SCANNER OBJECT
ACCEPT USER QUERY
CALL INVENTORY SEARCH METHOD FROM INVENTORY CLASS
INVENTORY SEARCH METHOD RETURN AN ARRAYLIST OF MATCHING ITEMS
IF ARRAYLIST FROM INVENTORY SEARCH METHOD IS NOT EMPTY{
PRINT AND NUMBER EACH MATCHING ITEM's PROPERTIES FROM ARRAYLIST <- I'm struck here!
CREATE SCANNER OBJECT 2
DO-WHILE LOOP for INPUT VALIDATION (ACCEPT ONLY POSITIVE INTEGER AND INTEGER MUST NOT BE LARGER THAN ARRAYLIST SIZE)
ACCEPT USER SELECTION
CALL ADD ITEM TO SHOPPING CART METHOD FROM SHOPPINGCART CLASS
}
ELSE
NO MATCH FOUND!
}
the return results from inventory search varies:
for example, return results:
1. mars snickers
2. mars M&Ms
3. mars caramel
0. cancel
with the above how should how can make it user selectable without using switch case statements?