While Loops #64 (The Indicator was tricky!)

Code

/// Name: Amir Salehi
/// Period: 7
/// Program Name:Pin Lockout
/// File Name:PinLockout.java
/// Date Finished: 12/7/2015

import java.util.Scanner;

public class PinLockout
{
	public static void main( String[] args )
	{
		Scanner keyboard = new Scanner(System.in);
		int pin = 69335;
		int tries = 0;
        int max = 4;
        int left =  max - 1;

		System.out.println("WELCOME TO THE BANK OF AMIR.");
		System.out.print("ENTER YOUR PIN: ");
		int entry = keyboard.nextInt();
		tries++;

		while ( entry != pin && tries < max )
		{
			System.out.println("\nINCORRECT PIN. TRY AGAIN.");
			System.out.print("ENTER YOUR PIN: ");
            System.out.println("\nYOU HAVE " + left + "REMAINING!");
			entry = keyboard.nextInt();
			tries++;
            left--;
		}

		if ( entry == pin )
			System.out.println("\nPIN ACCEPTED. YOU NOW HAVE ACCESS TO YOUR ACCOUNT.");
		else if ( tries >= max )
			System.out.println("\nYOU HAVE RUN OUT OF TRIES. ACCOUNT LOCKED.");
	}
}
    

Picture(s) of the output

Assignment 7

Back to Homepage