Advertisement
MrDoyle

While) PIN Lockout

Nov 13th, 2020
890
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main
  4. {
  5.     public static void main( String[] args )
  6.     {
  7.         Scanner keyboard = new Scanner(System.in);
  8.         int pin = 12345;
  9.         int tries = 0;
  10.         int maxTries = 5;
  11.  
  12.         System.out.println("WELCOME TO THE BANK OF DOYLE.");
  13.         System.out.println("You have " + (maxTries - tries) + " entry attempts left");
  14.  
  15.         System.out.print("ENTER YOUR PIN: ");
  16.         int entry = keyboard.nextInt();
  17.         tries++;
  18.  
  19.         while ( entry != pin && tries < maxTries )
  20.         {
  21.             System.out.println("\nINCORRECT PIN. TRY AGAIN.");
  22.             System.out.println("You have " + (maxTries - tries) + " entry attempts left");
  23.             System.out.print("ENTER YOUR PIN: ");
  24.             entry = keyboard.nextInt();
  25.             tries++;
  26.  
  27.         }
  28.  
  29.         if ( entry == pin )
  30.             System.out.println("\nPIN ACCEPTED. YOU NOW HAVE ACCESS TO YOUR ACCOUNT.");
  31.         else if ( tries >= maxTries )
  32.             System.out.println("\nYOU HAVE RUN OUT OF TRIES. ACCOUNT LOCKED.");
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement