Assignment #64: PIN Lockout
Code (Three Attempts)
/// Name: Kiran O'Farrell
/// File name: Lockout.java
/// Program name: PIN Lockout
/// Date completed: 1/20/16
import java.util.Scanner;
public class Lockout {
public static void main( String[] args ) {
Scanner keyboard = new Scanner(System.in);
int pin = 12345;
int tries = 0;
System.out.println("WELCOME TO THE BANK OF JOSHUA.");
System.out.print("ENTER YOUR PIN: ");
int entry = keyboard.nextInt();
tries++;
while ( entry != pin && tries < 3 ) {
System.out.println("\nINCORRECT PIN. TRY AGAIN.");
System.out.print("ENTER YOUR PIN: ");
entry = keyboard.nextInt();
tries++;
}
if ( entry == pin )
System.out.println("\nPIN ACCEPTED. YOU NOW HAVE ACCESS TO YOUR ACCOUNT.");
else if ( tries >= 3 )
System.out.println("\nYOU HAVE RUN OUT OF TRIES. ACCOUNT LOCKED.");
}
}
Code (Four Attempts)
/// Name: Kiran O'Farrell
/// File name: Lockout.java
/// Program name: PIN Lockout
/// Date completed: 1/20/16
import java.util.Scanner;
public class Lockout {
public static void main( String[] args ) {
Scanner keyboard = new Scanner(System.in);
int pin = 12345;
int tries = 0;
System.out.println("WELCOME TO THE BANK OF JOSHUA.");
System.out.print("ENTER YOUR PIN: ");
int entry = keyboard.nextInt();
tries++;
while ( entry != pin && tries < 4 ) {
System.out.println("\nINCORRECT PIN. TRY AGAIN.");
System.out.print("ENTER YOUR PIN: ");
entry = keyboard.nextInt();
tries++;
}
if ( entry == pin )
System.out.println("\nPIN ACCEPTED. YOU NOW HAVE ACCESS TO YOUR ACCOUNT.");
else if ( tries >= 4 )
System.out.println("\nYOU HAVE RUN OUT OF TRIES. ACCOUNT LOCKED.");
}
}
Code (Variable Attempts)
/// Name: Kiran O'Farrell
/// File name: Lockout.java
/// Program name: PIN Lockout
/// Date completed: 1/20/16
import java.util.Scanner;
public class Lockout {
public static void main( String[] args ) {
Scanner keyboard = new Scanner(System.in);
int pin = 12345;
int tries = 0;
int allowed = 5
System.out.println("WELCOME TO THE BANK OF JOSHUA.");
System.out.print("ENTER YOUR PIN: ");
int entry = keyboard.nextInt();
tries++;
while ( entry != pin && tries < allowed ) {
System.out.println("\nINCORRECT PIN. TRY AGAIN.");
System.out.print("ENTER YOUR PIN: ");
entry = keyboard.nextInt();
tries++;
}
if ( entry == pin )
System.out.println("\nPIN ACCEPTED. YOU NOW HAVE ACCESS TO YOUR ACCOUNT.");
else if ( tries >= allowed )
System.out.println("\nYOU HAVE RUN OUT OF TRIES. ACCOUNT LOCKED.");
}
}
Picture of the output (3 Tries)
Picture of the output (4 Tries)
Picture of the output (Variable Tries)