|
-
December 7th, 2009, 02:37 AM
#1
help regarding input dialog
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?
-
December 7th, 2009, 09:51 AM
#2
Re: help regarding input dialog
Code:
int i = 1;
String question = "Enter Quantity of Item " + i;
increment i as required
------
If you are satisfied with the responses, add to the user's rep!
-
December 7th, 2009, 09:51 AM
#3
Re: help regarding input dialog
You have a loop counter that increments with each iteration of the loop and you concatenate the loop counter with the message text ie:
Code:
String msg = "Enter Quantity of Item "+loop;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|