System.out.print("\nEnter the Preset password: "); int i = Integer.parseInt(getKeyboardBuffer()); Password pass = new Password(i); while (pass.getTriesLeft() > 0) { System.out.println("Enter password:"); pass.verify(Integer.parseInt(getKeyboardBuffer())); } }
private static String getKeyboardBuffer() { String s = ""; try { s = new BufferedReader(new InputStreamReader(System.in)).readLine(); }catch (IOException e) { System.out.println(e); } return s; } }
class Password{ private int magic = 314159; // digits for pi private int grace = 3; private int attempts = 0;
public Password(int password) { magic = password; }
public int getTriesLeft(){ return (grace - attempts); }