CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2009
    Posts
    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?

  2. #2
    Join Date
    Apr 2007
    Posts
    425

    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!

  3. #3
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    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
  •  





Click Here to Expand Forum to Full Width

Featured