jeudi 14 janvier 2021

Java Bank Program - How to deduct from the balance

i have this simple bank program where you can check your balance, deposit, and withdraw. this is a loop by the way so you can make multiple transactions

char anotherTransact, option;
    int balance;
    double deposit, withdraw;
    
    
    do {
    System.out.println("\nWelcome to ABC BANK \n");
    
    System.out.println("B - Check for Balance");
    System.out.println("D - Make Deposit");
    System.out.println("W - Make Withdraw");
    System.out.println("Q - Quit");
    
    
        System.out.print("\nSelect an option : ");
        option = scan.next().charAt(0);
        
        
        balance = 100000; 
        if ((option == 'B') || (option == 'b')) {
            System.out.println("\nYour current balance is " +balance);
        }
        
        else if ((option == 'D') || (option == 'd')) {
            System.out.print("\nEnter amount to Deposit : ");
            deposit = scan.nextDouble();
            if (deposit > 1) {
                System.out.println("Deposit Transaction is successfully completed.");
                double newBalance = 100000 + deposit; 
            }
            else if (deposit > 500000) {
                System.out.println("Deposit Amount must not be greater than 500,000");
            }
            else {
                System.out.println("Deposit must be greater than zero");
            }
        }
        
        else if ((option == 'W') || (option == 'w')) {
            System.out.print("\nEnter amount to Withdraw : ");
            withdraw = scan.nextDouble();
            if (withdraw % 100 == 0) {
                System.out.println("Withdrawal Transaction is successfully completed.");
                
            }
            else if (withdraw > 150000) {
                System.out.println("Withdrawal Amount must not be greater then 150,000");
            }
            else {
                System.out.println("Withdrawal Amount must be greater than zero");
            }
        }
        
        else {
            System.out.println("\nInvalid entry, enter any valid option : (B/D/W/Q)");
        }
        
        System.out.print("\nWant to Transact another (Y/N?) ");
        anotherTransact = scan.next().charAt(0);        
    }
    
    while ((anotherTransact == 'Y') || (anotherTransact =='y'));

the problem is that when i choose the withdraw option, i don't know how it should deduct the balance in the next bank transaction and also to add a deposit in the balance.

like for example, i would deposit $40 in the bank. then make a new transaction to open my balance that should add up the $40 i deposited. how can i add the deposited money in my balance? and also how to deduct it when i withdraw?

Aucun commentaire:

Enregistrer un commentaire