Question: package lab1; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class PasscodeCracker { public static void main(String[] args) { try { // Open the file that

package lab1;

import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner;

public class PasscodeCracker {

public static void main(String[] args) { try { // Open the file that contains the secret // TODO: Create a file called passcode containing a string Scanner pwdscan = new Scanner(new File("passcode.txt")); // TODO: Read the secret in from the file pwdscan.close(); // TODO: Decide how many tries the user can have and store it in an integer

// TODO: create a while loop for your passcode cracker game // TODO: Print the password as stars (e.g. if the password is "hello", print *****)

// TODO: within the while loop ask the user to guess a character // TODO: If guessed correctly, we reveal part of the hidden password and print the passcode // TODO: If all characters are revealed, break

// TODO: If character is not guessed correctly, print try again // TODO: For both cases reduce the number of tries and if the tries == 0, break // TODO: If the password is revealed, print "Congratulations, the password is ..." // TODO: If the password is not revealed, print "Sorry you failed :("

} catch (FileNotFoundException e) { System.out.println("File Not Found"); e.printStackTrace(); }

}

}

code and explanation thanks

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!