Click to See Complete Forum and Search --> : help regarding input dialog


doyousmellcarrots
December 7th, 2009, 01:37 AM
I'm doing a practice exercise in my Java textbook that is confusing me.
I'm supposed to write a do...while statement that uses the JOptionPane.showInputDialog method to retrieve the quantity, name and and price of a food item in three different dialog boxes. the program is supposed to do this 3 times for a purchase of 3 items total. where I get stuck is when the book tells me I need to "use the value of variable counter in the input dialog prompts to indicate that the user is inputting information for the first, second or third item." how can I change input = JOptionPane.showInputDialog( null, "Enter Quantity of Item 1");
to contain ( null, "Enter Quantity of Item 2"); and ( null, "Enter Quantity of Item 3"); and so on and so forth without writing the code for 9 different JOptionPane Input Dialog boxes?

Deliverance
December 7th, 2009, 08:51 AM
int i = 1;
String question = "Enter Quantity of Item " + i;


increment i as required

keang
December 7th, 2009, 08:51 AM
You have a loop counter that increments with each iteration of the loop and you concatenate the loop counter with the message text ie:

String msg = "Enter Quantity of Item "+loop;