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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started