jeudi 21 février 2019

Java - IF Statement only Returning the Else Clause

So the issue is with my withdraw method, for some reason, my code's outputting:

ADL
826501829
250.0
471.0
Balance is currently:40.0
There aren't enough funds.
There aren't enough funds.

I'm not very familiar with Java, so can't quite see why it's not outputting the right option from the IF statement public class BankAcc {

    String accountName;
    int accountNumber;
    float accountOverdraft;
    float currentBalance;

    public BankAcc(String accountName, int accountNumber, float accountOverdraft, float currentBalance) {
        System.out.println(accountName);
        System.out.println(accountNumber);
        System.out.println(accountOverdraft);
        System.out.println(currentBalance);
    }

    public void deposit(float depositAmnt){
        currentBalance = currentBalance + depositAmnt;
        System.out.println("Balance is currently:" + currentBalance);
    }

    public void withdraw(float withdrawAmnt){
        if (withdrawAmnt <= currentBalance){
            currentBalance = currentBalance - withdrawAmnt;
            System.out.println("Balance is currently:" + currentBalance);
        } else {
            System.out.println("There aren't enough funds.");
        }
    }

    public static void main(String []args){
        BankAcc myBankAcc = new BankAcc("ADL",826501829, 250, 471);
        myBankAcc.deposit(40);
        myBankAcc.withdraw(99);
        myBankAcc.withdraw(999);
    }
}

Aucun commentaire:

Enregistrer un commentaire