_MuradPro_

Bank

Mar 29th, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.13 KB | None | 0 0
  1.  
  2. public class Bank {
  3.     String name;
  4.     static Account[] accounts = new Account[80];
  5.     static int current = 0;
  6.     static String manager = "Doctor Who";
  7.     public static void main(String[] args) {
  8.         Account acnt1 = new Account("Murad", 189863345L, 100.0, false);
  9.         System.out.println("Is account of " + acnt1.getName() + " added? " + createAccount(acnt1));
  10.        
  11.         Account acnt2 = new Account("Amos", 1242426776L, 200.0, true);
  12.         System.out.println("Is account of " + acnt2.getName() + " added? " + createAccount(acnt2));
  13.        
  14.         Account acnt3 = new Account("Murad", 189863345L, 1000000.0, true);
  15.         System.out.println("Is account of " + acnt3.getName() + " added? " + createAccount(acnt3));
  16.        
  17.         System.out.println("*********************************");
  18.         System.out.println("Welcome to Nucha-plata bank");
  19.         System.out.println("Current manager:" + manager + "***");
  20.        
  21.         System.out.println("Is " + manager + " corrupted? " + corrupted());
  22.         System.out.println("*********************************");
  23.        
  24.         Account pica = new Account("Picachu", 111111111L, 1000000.0, true);
  25.         createAccount(pica);
  26.         System.out.println("1000 euro to " + pica.getName() + " success? " + deposit(pica, "Doctor Who", 1000));
  27.     }
  28.    
  29.     public static boolean createAccount(Account account) {
  30.         if(current == 79) {
  31.             System.out.println("The bank os full, can't add new user\nSorry");
  32.             return false;
  33.         }
  34.         String owner = account.getName();
  35.         for(int i=0; i<current; i++) {
  36.             if(accounts[i].getName().equals(owner) && accounts[i].getId() == account.getId()) {
  37.                 System.out.println("A user with these details already exists\nNo account was created");
  38.                 return false;
  39.             }
  40.         }
  41.         accounts[current] = account;
  42.         current++;
  43.         return true;
  44.     }
  45.     public static void change_management(String name) {
  46.         manager = name;
  47.     }
  48.     public static boolean corrupted() {
  49.         for (int i=0; i<current; i++) {
  50.             if(accounts[i].getName().equals(manager) && accounts[i].isVip() == true)
  51.                 return true;
  52.         }
  53.         return false;
  54.     }
  55.     public static boolean withdrawal(Account account, String teller, double amount) {
  56.         if(!teller.equals(manager))
  57.             return false;
  58.         for(int i=0; i<current; i++) {
  59.             if(accounts[i].getName().equals(account.getName()) && accounts[i].getId() == account.getId()) {
  60.                 if(accounts[i].getBalance() < amount) {
  61.                     System.out.println("Only " + accounts[i].getBalance() + " was withdrawaled");
  62.                     accounts[i].setBalance(0);
  63.                 }
  64.                 else {
  65.                     accounts[i].setBalance(accounts[i].getBalance() - amount);
  66.                     System.out.println("Successfull withdrawal");
  67.                 }
  68.             }
  69.         }
  70.         System.out.println("There is not such an account in our bank!");
  71.         return false;
  72.     }
  73.     public static boolean deposit(Account account, String teller, double amount) {
  74.         if(!teller.equals(manager))
  75.             return false;
  76.         for(int i=0; i<current; i++) {
  77.             if(accounts[i].getName().equals(account.getName()) && accounts[i].getId() == account.getId()) {
  78.                 accounts[i].setBalance(accounts[i].getBalance() + amount);
  79.                 System.out.println("Successfull deposit"); 
  80.                 return true;
  81.             }  
  82.         }
  83.         System.out.println("There is not such an account in our bank!");
  84.         return false;
  85.     }
  86. }
Add Comment
Please, Sign In to add comment