Advertisement
TheRightGuy

Advice?

Feb 16th, 2022
660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.57 KB | None | 0 0
  1. public class App {
  2.  
  3.     public static void main(String[] args) {
  4.         BankingSystem bankingSystem = new BankingSystem();
  5.         bankingSystem.start();
  6.     }
  7. }
  8.  
  9.  
  10. import java.math.BigInteger;
  11. import java.util.ArrayList;
  12. import java.util.Random;
  13. import java.util.Scanner;
  14.  
  15. public class BankingSystem {
  16.     private final ArrayList<Customer> customers = new ArrayList<>();
  17.     private final Scanner input = new Scanner(System.in);
  18.     private final BigInteger randomID = new BigInteger(53, new Random());
  19.     private final  Customer customer = new Customer();
  20.     public void start() {
  21.  
  22.         Customer person = new Customer("Man",200);
  23.         Customer tom = new Customer("Tom",500);
  24.         addCustomer(person);
  25.         addCustomer(tom);
  26.  
  27.         for (Customer s : customers) {
  28.             System.out.println(s.getName() + " " + s.getBalance() + " " + s.getAccountID());
  29.         }
  30.         bankActions();
  31.     }
  32.  
  33.     private void bankActions() {
  34.         System.out.println("If you wish to deposit money press 1 \nIf you wish to withdraw money press 2\nTo exit press 3");
  35.         int atm = input.nextInt();
  36.         while (atm != 3) {
  37.             if (atm == 1) {
  38.                 depositMoney(customer);
  39.             } else if (atm == 2) {
  40.                 withdrawMoney(customer);
  41.             }
  42.             atm = input.nextInt();
  43.         }
  44.     }
  45.  
  46.     private void withdrawMoney(Customer customer) {
  47.         System.out.println("How much do you want to withdraw?");
  48.         int balance = input.nextInt();
  49.         balance = balanceCondition(balance, customer.getBalance(), "You don't have enough money in the account.\nYour current balance is " + customer.getBalance());
  50.         int withdraw = customer.getBalance() - balance;
  51.         customer.setBalance(withdraw);
  52.         System.out.println("Your current balance is $" + customer.getBalance());
  53.     }
  54.  
  55.     private void addCustomer(Customer customer) {
  56.         customer.setName(customer.getName());
  57.         customer.setBalance(customer.getBalance());
  58.         customer.setAccountID(randomID);
  59.         customers.add(customer);
  60.     }
  61.  
  62.     private void depositMoney(Customer customer) {
  63.         System.out.println("How much do you want to add to your account?");
  64.         int balance = input.nextInt();
  65.         int BALANCE_LIMIT = 999999999;
  66.         balance = balanceCondition(balance, BALANCE_LIMIT, "You can not add that much money at once. Add below $999999999");
  67.         int addingToBalance = customer.getBalance() + balance;
  68.         customer.setBalance(addingToBalance);
  69.         System.out.println("Your current balance is $" + customer.getBalance());
  70.     }
  71.  
  72.     private int balanceCondition(int balance, int i, String s) {
  73.         while (balance > i) {
  74.             System.out.println(s);
  75.             balance = input.nextInt();
  76.         }
  77.         return balance;
  78.     }
  79. }
  80.  
  81. import java.math.BigInteger;
  82.  
  83. public class Customer {
  84.  
  85.     private String name;
  86.     private int balance;
  87.     private BigInteger accountID;
  88.  
  89.     public Customer(String name, int balance){
  90.         this.name = name;
  91.         this.balance = balance;
  92.     }
  93.  
  94.     public Customer() {}
  95.  
  96.     public String getName() {
  97.         return name;
  98.     }
  99.  
  100.     public void setName(String name) {
  101.         this.name = name;
  102.     }
  103.  
  104.     public int getBalance() {
  105.         return balance;
  106.     }
  107.  
  108.     public void setBalance(int balance) {
  109.         this.balance = balance;
  110.     }
  111.  
  112.     public BigInteger getAccountID() {
  113.         return accountID;
  114.     }
  115.  
  116.     public void setAccountID(BigInteger accountID) {
  117.         this.accountID = accountID;
  118.     }
  119. }
  120.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement