Programming Drill #9

Due: Wednesday, October 3
Goal:  Practice using an integrated debugger

For this drill you must use NetBeans (or some other IDE with a debugger).   First create a NetBeans project.  Here is an attempted solution, which you can paste inside the main method of your NetBeans project. You will have to import java.util.Scanner near the top of your program.

		String secretPassword;
		Scanner keyboard = new Scanner(System.in);
		boolean correctPassword = false;

		while (!correctPassword)
		{
			System.out.println("Enter the secret password to proceed.");
			secretPassword = keyboard.next();
			if (secretPassword == "secret")
			{
				System.out.println("You entered the correct password!");
				correctPassword = true;
			}
			else
			{
				System.out.println("Incorrect password. Try again.");
			}
		}
    

This program is supposed to make the user type in a word until the secret password of "secret" is entered. However, it doesn't quite work.  Use the debugger to find the error and correct it.  You can start by setting a breakpoint and stepping through the program line by line, looking at variables as you go. Even if you can spot the error by just looking at the program, use the debugger to get some practice for how it works.

Show the working code to your instructor or email it to kenrick@uaa.alaska.edu by the end of the day.