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.

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...

Edited by Reverend Jim: Fixed formatting

6 Years
Discussion Span
Last Post by Eric Cute

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.

Edited by Eric Cute: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.