Advertisement
Guest User

Untitled

a guest
Nov 28th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.44 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4. public class Lab9_p2 {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner input = new Scanner(System.in);
  8.  
  9.         int[] random = new int[10];
  10.         int[] number = new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  11.         int[] pIN = new int[10];
  12.         int[] password = new int[]{7, 3, 4, 6, 0};
  13.         char[] inNumb = new char[10];
  14.         String[] inNumb1 = new String[10];
  15.  
  16.         for (int row = 0; row < random.length; row++) {
  17.             random[row] = (int) Math.ceil(Math.random() * 3);
  18.  
  19.         }
  20.  
  21.         for (int row = 0; row < pIN.length - 5; row++) {
  22.             pIN[row] = (int) Math.ceil(Math.random() * 3);
  23.  
  24.         }
  25.         System.out.print("Authentication Process\n\n");
  26.        
  27.        
  28.         System.out.print("Number : ");
  29.         for (int row = 0; row < number.length; row++) {
  30.             System.out.printf("%2d", number[row]); // number pad row
  31.  
  32.         }
  33.  
  34.         System.out.println();
  35.         System.out.print("Random : ");
  36.         for (int row = 0; row < random.length; row++) {
  37.             System.out.printf("%2d", random[row]); // random number row
  38.  
  39.         }
  40.  
  41.        
  42.         //***********************************************************************
  43.         // Gets user input(String) Converts to Char, then Char value conversion.
  44.         System.out.println();
  45.         System.out.println();
  46.         System.out.print("Enter PIN sequence:");
  47.         String user = input.next();
  48.        
  49.         for (int i = 0; i < user.length(); i++) {  //converts string into char
  50.             inNumb[i] = user.charAt(i);
  51.        
  52.         }
  53.         System.out.println();
  54.         for (int i = 0; i < user.length(); i++) { //converts from Char to value of char  
  55.             inNumb1[i] = String.valueOf(inNumb[i]);
  56.        
  57.         }
  58. //*******************************************************************************
  59.         boolean key = false;
  60.         for (int row = 0, match = 0; row < password.length; row++) {
  61.  
  62.             if (random[password[row]] == Integer.parseInt(inNumb1[row])) {
  63.  
  64.                 match++;
  65.                 if (match == 5) {
  66.  
  67.                     key = true;
  68.                 }
  69.             }
  70.         }
  71.         if (key) {
  72.             System.out.print("Correct PIN - authentication confirmed.");
  73.         } else {
  74.             System.out.print("Improper PIN - authentication denied.");
  75.         }
  76.  
  77.     }
  78. }
  79. // int[] password = new int []{7,3,4,6,0}; (password)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement