Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2014
    Posts
    4
    Rep Power
    0

    Default Help with Do While & JOptionPane

    is there anyway I can write a do while statement for this program. I haven't seen anyway to do it anywhere.

    Java Code:
    import javax.swing.JOptionPane;
    
    public class History {
    
    
        public static void main(String[] args) 
        {
    
           //First Question: What is the capital of Mexico? 
            String[] question1 = {"Mexico City", "Paris"    //The choseable answers are made using String
                    ,"Washington D.C", "Tokyo"};
    
           
            String MexicoCapital = (String)JOptionPane.showInputDialog(null, "What is the capital of Mexico?:"
                    , "Question 1 of 10", JOptionPane.QUESTION_MESSAGE // question number is diplayed on top of text box
                    , null, question1, question1[0]); //Choices are called and displayed using joptionpane
    
           
            if (MexicoCapital == null)
            {
                JOptionPane.showMessageDialog(null, "You didn't pick a city!");
            }
            else 
            {
                
                String funfact = "";
                switch (MexicoCapital)
                {
                    case "Mexico City":
                        funfact = "Correct";
                        break;
                    case "Paris":
                        funfact = "Incorrect! Paris is the capital of France";
                        break;
                    case "Washington D.C":
                        funfact = "Incorrect! Washington D.C is the capital of the United States";
                        break;
                    case "Tokyo":
                        funfact = "Incorrect! Tokyo is the capital of Japan";
                        break;
                    default:
                        funfact = "Something went wrong with picking an answer ";
                        break;
                }
                JOptionPane.showMessageDialog(null, funfact);
            }

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default Re: Help with Do While & JOptionPane

    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    Join Date
    Feb 2014
    Posts
    4
    Rep Power
    0

    Default Re: Help with Do While & JOptionPane

    sory im just frustrated. Did i break a rule?

  4. #4
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default Re: Help with Do While & JOptionPane

    Yep, you did. Read this : The problems with cross-posting
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  5. #5
    Join Date
    Feb 2014
    Posts
    4
    Rep Power
    0

    Default Re: Help with Do While & JOptionPane

    how do i delete the post

Similar Threads

  1. Help with JOptionPane
    By javaman1 in forum New To Java
    Replies: 6
    Last Post: 11-13-2010, 11:40 PM
  2. need help for JOptionPane....
    By keycoffee in forum New To Java
    Replies: 1
    Last Post: 02-09-2010, 09:59 AM
  3. JOptionpane
    By tommyyyy in forum New To Java
    Replies: 2
    Last Post: 03-20-2009, 09:33 AM
  4. JOptionPane
    By Mir in forum New To Java
    Replies: 5
    Last Post: 11-29-2008, 03:04 AM
  5. JOptionPane
    By whosadork in forum New To Java
    Replies: 2
    Last Post: 10-23-2008, 03:17 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •