Advertisement
Ramdan51-062

Toll

Oct 26th, 2017
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Toll
  4. {
  5.     private boolean userAuthenticated;
  6.     private int currentAccountNumber;
  7.     private TollDatabase tollDatabase;
  8.     Scanner input = new Scanner(System.in);
  9.     public Toll()
  10.     {
  11.         userAuthenticated = false;
  12.         currentAccountNumber = 0;
  13.         tollDatabase = new TollDatabase();
  14.     }
  15.    
  16.     public void run()
  17.     {
  18.         while(true)
  19.         {
  20.             while(!userAuthenticated)
  21.             {
  22.                 System.out.print("\nWelcome!");
  23.                 AuthenticateUser();
  24.             }
  25.             Transaction cash = null;
  26.             cash = new CashCheck(currentAccountNumber, tollDatabase);
  27.             cash.execute();
  28.             userAuthenticated = false;
  29.             currentAccountNumber = 0;
  30.             System.out.print("\nThank You! Come Again!");
  31.         }
  32.     }
  33.    
  34.     private void AuthenticateUser()
  35.     {
  36.         System.out.print("\nPlease enter your account number: ");
  37.         int accountNumber = input.nextInt();;
  38.         System.out.print("\nPlease enter your PIN: ");
  39.         int pin = input.nextInt();;
  40.        
  41.         userAuthenticated = tollDatabase.authenticateUser(accountNumber, pin);
  42.        
  43.         if(userAuthenticated)
  44.         {
  45.             currentAccountNumber = accountNumber;
  46.         }
  47.        
  48.         else System.out.print("\nInvalid account or PIN. Please try again");
  49.     }
  50.    
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement