Write a program that will ask for a password. If the password is entered correctly, a message should be displayed like “You may enter”; otherwise after 10 tries display a count down from 10 to 0 then a message that the hard drive is being wiped out should be displayed. (Have some fun, add this .jar file to your windows startup, and freak out your parents.) Some “sleep” code will be covered in class so that the count occurs every second.
Example:

Enter Password (10): bubba
Enter Password (9): stud
…….
Enter Password (1): stop
10 9 8 7 6 5 4 3 2 1 0
Your Hard Drive is now being erased....

So my program looks like this

import javax.swing.JOptionPane;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Kevin
 */
public class PassWordProgram {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // variable
        String passwordinput;
        passwordinput = getLineFromUser();

        JOptionPane.showInputDialog(" Insert Password");


        if (passwordinput.equals("Pokemon")) {
            JOptionPane.showMessageDialog(null, "Correct PassWord");
        } else {
            JOptionPane.showMessageDialog(null, "Wrong Password");


            JOptionPane.showMessageDialog(null, (""));
            JOptionPane.showMessageDialog(null, "Your HardDrive is now being Erased");
        }


    }

    private static String getLineFromUser() {
        throw new UnsupportedOperationException("Not yet implemented");
    }
}

}

I get errors in my program and also if anyone can help me out in the 10 tries then it starts doing the 10 9 8 7 time sequence...

Recommended Answers

All 2 Replies

1. Please wrap your code in code tags
2. Post the text of the error message

Just create an int counter so that everytime wrong password is entered then you add 1 to this counter. Check if it is < 11. If not, then call your method where you show your dialogbox and repeat the process until user gets the password or until he exceeded 10 tries.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.