0

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?

Edited by jnewbie: n/a

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by JeffGrigg
0

You might be over-thinking this. Relax. Take it a step at a time.

To answer your question...
If you have an ArrayList containing "mars snickers", "mars M&Ms" and "mars caramel" then you might want to loop through the elements of the list and print each one. Note that "item #1" ("mars snickers") will be at index ZERO in the ArrayList.

Now at the next step, if the user enters a positive integer value between one and three (which is the length of the ArrayList), there is a way you could find the corresponding element of the ArrayList, given that integer numeric value. ;->

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.