Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Program closes?

  1. #1
    New to the CF scene
    Join Date
    May 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Program closes?

    I'm trying to make a program where you type a password, and it either tells you your wrong, or if you get it right, it tells you to type "Stop" or "Score". If you type score, it tells you how many tries it took for you to get the password correct. If you type stop, it will close the program. Whenever you get a wrong answer, it closes the program, instead of keeping it open like the loop SHOULD do... Here is the code (This probably isn't the best way I could do this, I have only been learning java for a few days)
    package javaapplication7;

    import javax.swing.JOptionPane;

    public class JavaApplication7
    {
    public static void main(String[] args)
    {
    String input;
    String message = "TYPE DA PASSWORD!!!\n"
    + "Fail 3 Times And Get Called Stupid.\n"
    + "Fail 5 Times And Get Called Retarded.\n"
    + "Fail 10 Times And Your Computer Explodes. Not Really \n";
    boolean goodpw = false;
    int fails = 0;

    while (!goodpw)
    {
    input = JOptionPane.showInputDialog(message);

    if (input.equals("Farted"))
    {
    message = "CRAP YOU GOT MAH PASSWORD!!!\nIf You Want To Stop, Type Stop."
    + "\n"
    + "\n"
    + "\n"
    + "\n";
    }
    else
    {
    if (input.equals("Stop"));
    {
    goodpw = true;
    }
    if (input.equals("Score"))
    {
    goodpw = false;
    if (fails == 0)
    {
    message = "Wow... YOU DIDN'T MESS UP AT ALL!";
    }
    if (fails > 0)
    {
    message = "You Only Messed Up ONCE!";
    }
    if (fails > 1)
    {
    message = "Great Job! You Got The Password In 2 Tries!";
    }
    if (fails > 2)
    {
    message = "Nice! You Won In 3 Tries!";
    }
    if (fails > 3)
    {
    message = "Pretty Good. You Got It In 4 Tries.";
    }
    if (fails > 4)
    {
    message = "Decent. You Got The Password In 5 Tries.";
    }
    if (fails >= 5)
    {
    message = "You Got The Password In 6 Or More Tries.";
    }
    }
    if(fails < 3)
    {
    message = "YOU GOT IT WRONG!!! Type the password!!!";
    }
    else
    if(fails < 5)
    {
    message = "You Are Kinda Retarded. TYPE THE RIGHT PASSWORD!!!";
    }
    else
    {
    message = "IF YOU DONT TYPE THE RIGHT PASSWORD WITHIN 5 SECONDS, YOUR COMPUTER WILL E X P L O D E!!!";
    }
    fails = fails+1;
    if (fails < 15)
    {
    goodpw = true;
    }
    }
    }
    }
    }

  • #2
    New to the CF scene
    Join Date
    May 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Derp couldn't find the edit button
    Here's the code:
    Code:
    package javaapplication7;
    
    import javax.swing.JOptionPane;
    
    public class JavaApplication7 
    {
        public static void main(String[] args) 
        {
            String input;
            String message = "TYPE DA PASSWORD!!!\n"
                    + "Fail 3 Times And Get Called Stupid.\n"
                    + "Fail 5 Times And Get Called Retarded.\n"
                    + "Fail 10 Times And Your Computer Explodes. Not Really :D\n";
            boolean goodpw = false;
            int fails = 0;
            
            while (!goodpw)
            {
                input = JOptionPane.showInputDialog(message);
                
                if (input.equals("Farted"))
                {                
                    message = "CRAP YOU GOT MAH PASSWORD!!!\nIf You Want To Stop, Type Stop."
                            + "\n"
                            + "\n"
                            + "\n"
                            + "\n";                
                }
                else
                {
                    if (input.equals("Stop"));
                    {
                        goodpw = true;
                    }
                    if (input.equals("Score"))
                    {
                        goodpw = false;
                        if (fails == 0)
                        {
                            message = "Wow... YOU DIDN'T MESS UP AT ALL!";
                        }    
                        if (fails > 0)
                        {
                            message = "You Only Messed Up ONCE!";
                        }
                        if (fails > 1)
                        {
                            message = "Great Job! You Got The Password In 2 Tries!";
                        }
                        if (fails > 2)
                        {
                            message = "Nice! You Won In 3 Tries!";
                        }
                        if (fails > 3)
                        {
                            message = "Pretty Good. You Got It In 4 Tries.";
                        }
                        if (fails > 4)
                        {
                            message = "Decent. You Got The Password In 5 Tries.";
                        }
                        if (fails >= 5)
                        {
                            message = "You Got The Password In 6 Or More Tries.";
                        }    
                    }
                    if(fails < 3)
                    {
                        message = "YOU GOT IT WRONG!!! Type the password!!!";
                    }
                    else
                    if(fails < 5)
                    {
                        message = "You Are Kinda Retarded. TYPE THE RIGHT PASSWORD!!!";
                    }
                    else
                    {
                        message = "IF YOU DONT TYPE THE RIGHT PASSWORD WITHIN 5 SECONDS, YOUR COMPUTER WILL E X P L O D E!!!";
                    }                             
                     fails = fails+1;
                    if (fails < 15)
                    {
                        goodpw = true;
                    }
                }
            }
        }
    }


  •  

    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
    •