Question: I just stucked here and please help me complete this and make some explanation package Lab1; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class PasscodeCracker
I just stucked here and please help me complete this and make some explanation
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 System.out.println("test.txt file:"); while(pwdscan.hasNextLine()) { System.out.println(pwdscan.nextLine()); } pwdscan.close(); // TODO: Decide how many tries the user can have and store it in an integer int x = 5; // TODO: create a while loop for your passcode cracker game while( x > 0 ); // 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(); }
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
