dawciobiel

Bankomat

Apr 15th, 2020
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.98 KB | None | 0 0
  1. import java.math.BigDecimal;
  2. import java.math.BigInteger;
  3. import java.util.Vector;
  4.  
  5. public class Bankomat {
  6.  
  7.     private static Vector<Account> accounts = new Vector<>(10);
  8.     private static Account loggedInAccountOwner;
  9.  
  10.     public static void main(String[] args) {
  11.         // TODO Auto-generated method stub
  12.  
  13.     }
  14.  
  15.     private void initializeBankomatData() {
  16.         // Create 5 random generated accounts
  17.         accounts.add(new Account(new BigInteger("1000000001"), "Jak Kowalski", new BigDecimal("35.10")));
  18.         accounts.add(new Account(new BigInteger("1000000002"), "Jak Nowak", new BigDecimal("56.60")));
  19.         accounts.add(new Account(new BigInteger("1000000003"), "Henryk Sosna", new BigDecimal("572.25")));
  20.         accounts.add(new Account(new BigInteger("1000000004"), "Aleksander Kosogłowy", new BigDecimal("134.30")));
  21.         accounts.add(new Account(new BigInteger("1000000005"), "Mohinder Sarash", new BigDecimal("999900.00")));
  22.     }
  23.  
  24.     private static boolean login(Account accountTryingToLogOn) {
  25.         if (verifyAccountOwner(accountTryingToLogOn)) {
  26.             // success
  27.             loggedInAccountOwner = accountTryingToLogOn;
  28.             return true;
  29.         } else {
  30.             // fail, wrong login details (account number or pin) or account doesnt exist at all.
  31.             loggedInAccountOwner = null;
  32.             return false;
  33.         }
  34.     }
  35.  
  36.     private static boolean verifyAccountOwner(Account accToVerify) {
  37.         for (Account account : accounts) {
  38.             if (account.getAccountNumber().equals(accToVerify.getAccountNumber())) { // if
  39.                                                                                         // that
  40.                                                                                         // accout
  41.                                                                                         // number
  42.                                                                                         // exist...
  43.                 if (account.getPin() == accToVerify.getPin()) { // if pin is
  44.                                                                 // correct..
  45.                     return true; // ..mean that account exist.
  46.                 }
  47.             }
  48.             return false;
  49.         }
  50.         return false; // Mean that account doesnt exist in data base.
  51.     }
  52.  
  53.     private static void logout() {
  54.     loggedInAccountOwner = null;
  55. }
  56.    
  57.     private static BigDecimal getAccoutnBallance() {
  58.         return loggedInAccountOwner.getBallance();
  59.     }
  60. }
Add Comment
Please, Sign In to add comment