accumulating totals in CheckingAccount class is not outputting correct total
I am not sure what I am doing wrong. I know I am not passing the value correctly, but can not figure it out and have worked many hours trying to resolve it, but nothing works.
abstract class BankAccount {
double balance = 0.0;
double totalBalance;
double deposit;
public void setBalance(double balance) {
this.balance = balance;
}
public double getBalance(double balance) {
return this.balance;
}
public void setTotalBalance(double totalBalance) {
this.totalBalance = totalBalance;
}
public double getTotalBalance(double totalBalance) {
return deposit + balance;
}
public void setDeposit(double deposit) {
this.deposit = deposit;
}
public double getDeposit(double deposit) {
return this.deposit;
}
public abstract void debitAccount();
public abstract void creditAccount();
}
import java.util.ArrayList;
public class BankAccountTestDrive {
public static void main(String[] args) {
ArrayList<BankAccount> bankAccountArray = new ArrayList<BankAccount>();
BankAccount checkingAccount = new CheckingAccount();
BankAccount autoLoan = new AutoLoan();
autoLoan.creditAccount();
checkingAccount.creditAccount();
checkingAccount.setBalance(62.00);
checkingAccount.setDeposit(6.00);
checkingAccount.setDeposit(10.00);
checkingAccount.setDeposit(4.00);
bankAccountArray.add(checkingAccount);
autoLoan.setBalance(30.00);
autoLoan.setBalance(2000.00);
bankAccountArray.add(autoLoan);
for (BankAccount bankaccount : bankAccountArray) {
bankaccount.creditAccount();
}
System.out.println("Checkiing Balance " + checkingAccount.getBalance(0));
System.out.println("Auto loan Balance " + autoLoan.getBalance(0) + "\n");
System.out.println("Total accounts: " + bankAccountArray.size());
}
}
class CheckingAccount extends BankAccount {
public void creditAccount() {
balance = deposit += balance;
}
@Override
public void debitAccount() {
balance -= balance;
}
}
each deposit needs to be added to the balance to accumulate a total for checkingAccount and the same for AutoLoan.
expected output: Checkiing Balance 70.0 Auto loan Balance 1970.0
Total accounts: 2