Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class App {
- public static void main(String[] args) {
- BankingSystem bankingSystem = new BankingSystem();
- bankingSystem.start();
- }
- }
- import java.math.BigInteger;
- import java.util.ArrayList;
- import java.util.Random;
- import java.util.Scanner;
- public class BankingSystem {
- private final ArrayList<Customer> customers = new ArrayList<>();
- private final Scanner input = new Scanner(System.in);
- private final BigInteger randomID = new BigInteger(53, new Random());
- private final Customer customer = new Customer();
- public void start() {
- Customer person = new Customer("Man",200);
- Customer tom = new Customer("Tom",500);
- addCustomer(person);
- addCustomer(tom);
- for (Customer s : customers) {
- System.out.println(s.getName() + " " + s.getBalance() + " " + s.getAccountID());
- }
- bankActions();
- }
- private void bankActions() {
- System.out.println("If you wish to deposit money press 1 \nIf you wish to withdraw money press 2\nTo exit press 3");
- int atm = input.nextInt();
- while (atm != 3) {
- if (atm == 1) {
- depositMoney(customer);
- } else if (atm == 2) {
- withdrawMoney(customer);
- }
- atm = input.nextInt();
- }
- }
- private void withdrawMoney(Customer customer) {
- System.out.println("How much do you want to withdraw?");
- int balance = input.nextInt();
- balance = balanceCondition(balance, customer.getBalance(), "You don't have enough money in the account.\nYour current balance is " + customer.getBalance());
- int withdraw = customer.getBalance() - balance;
- customer.setBalance(withdraw);
- System.out.println("Your current balance is $" + customer.getBalance());
- }
- private void addCustomer(Customer customer) {
- customer.setName(customer.getName());
- customer.setBalance(customer.getBalance());
- customer.setAccountID(randomID);
- customers.add(customer);
- }
- private void depositMoney(Customer customer) {
- System.out.println("How much do you want to add to your account?");
- int balance = input.nextInt();
- int BALANCE_LIMIT = 999999999;
- balance = balanceCondition(balance, BALANCE_LIMIT, "You can not add that much money at once. Add below $999999999");
- int addingToBalance = customer.getBalance() + balance;
- customer.setBalance(addingToBalance);
- System.out.println("Your current balance is $" + customer.getBalance());
- }
- private int balanceCondition(int balance, int i, String s) {
- while (balance > i) {
- System.out.println(s);
- balance = input.nextInt();
- }
- return balance;
- }
- }
- import java.math.BigInteger;
- public class Customer {
- private String name;
- private int balance;
- private BigInteger accountID;
- public Customer(String name, int balance){
- this.name = name;
- this.balance = balance;
- }
- public Customer() {}
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public int getBalance() {
- return balance;
- }
- public void setBalance(int balance) {
- this.balance = balance;
- }
- public BigInteger getAccountID() {
- return accountID;
- }
- public void setAccountID(BigInteger accountID) {
- this.accountID = accountID;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement