Advertisement
Guest User

Untitled

a guest
May 15th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 2.00 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Password {
  4.  
  5.     /**
  6.      * This program will allow the user to validate his PIN number without actually putting in his real PIN numbers.
  7.      */
  8.    
  9.     public static void main(String[] args) {
  10.     Scanner keyIn = new Scanner (System.in);   
  11.     int count = 0;
  12.     final int PASSWORD = 13379; // User's PIN number
  13.     int addition = 1;
  14.     int multiple = 3;
  15.     String comparePassword = Integer.toString(PASSWORD); // Used to compare user input with password.
  16.    
  17.    
  18.     //Print intro
  19.     System.out.println("--------------------------------------------------------");
  20.     System.out.println("           Welcome to Vansilli's Trust Bank");
  21.     System.out.println("--------------------------------------------------------");
  22.    
  23.    
  24.     System.out.println("\nPlease enter your 5 digit PIN based on the following:");
  25.    
  26.     //Set an array to print out the range of 10 numbers for the PIN.
  27.     String[] PIN = {"0",  "1",  "2",  "3",  "4",  "5",  "6",  "7",  "8",  "9"};
  28.     System.out.print("PIN: ");
  29.     for(int j=0;j<PIN.length;j++)
  30.         {
  31.             System.out.print(PIN[j] + "  ");
  32.         }
  33.    
  34.     //Generate 10 random numbers ranging from 1 to 3 under every digit.
  35.     System.out.print("\nNUM: ");
  36.     int[] Num = new int[10];
  37.     for (int index = 0; index<10; index++)
  38.         {
  39.             Num[index] = (int)(Math.random()*multiple + addition);
  40.             System.out.print(Num[index] + "  ");
  41.         }      
  42.    
  43.     //We ask the user to input his PIN.
  44.     System.out.print("\nYour PIN:");
  45.     int userInput = keyIn.nextInt();
  46.    
  47.     //Change the userInput into a string.
  48.     String compareUser = Integer.toString(userInput);
  49.    
  50.     for(int i = 0; i < 5; i++)
  51.         {
  52.             String s1 = Character.toString(comparePassword.charAt(i));
  53.             String s3 = Character.toString(compareUser.charAt(i));
  54.             for(int j = 0; j < 10; j++)
  55.                 {
  56.                     String s2 = PIN[j];
  57.                     String s4 = Integer.toString(Num[j]);
  58.                 if(s1.equals(s2))
  59.                 {
  60.                     if(s3.equals(s4))
  61.                     {
  62.                         count++;
  63.                     }
  64.                 }
  65.             }
  66.         }
  67.    
  68.     if(count == 5)
  69.         System.out.println("Correct!");
  70.     else
  71.         System.out.println("Invalid!");
  72.    
  73.     }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement