public class Account {
double currentBalance;
Account(double currentBalance) {
this.currentBalance = currentBalance;
}
double getBalance() {
return(this.currentBalance);
}
void deposit(double amount) {
this.currentBalance += amount;
}
void withdraw(double amount) {
this.currentBalance -= amount;
}
public String toString() {
return("Your current account balance is: $" + this.currentBalance);
}
}
public class SavingsAccount extends Account {
double interestRate;
SavingsAccount(double interestRate, double amount) {
super(amount);
this.interestRate = interestRate;
}
void addInterest(double interestRate) {
this.currentBalance = this.currentBalance + (this.currentBalance * (interestRate / 100));
}
public String toString() {
return("Your current account balance is: $" + this.currentBalance + ". Your interest rate is: " + this.interestRate + "%");
}
}
public class AccountTester {
public static void main(String[] args) {
System.out.println("Welcome to the COMP 251 BANK");
Account[] acc = new Account[10];
acc[0] = new Account (100000); // initial amount of 100k
System.out.println(acc[0].toString());
acc[0].deposit(50000); //deposit 50k
System.out.println("Current balance after depositing is: " + "$" + acc[0].getBalance());
acc[0].withdraw(10000);
System.out.println("Current balance after withdrawing is: " + "$" + acc[0].getBalance());
System.out.println();
System.out.println("CHECKING ACCOUNT");
acc[1] = new CheckingAccount(10000,50000); //overdraft limit of 1000, initial amount of 50k
System.out.println(acc[1].toString());
acc[1].deposit(20000); //I dont know what to do about the chequeDeposit
System.out.println("Current balance after depositing is: " + "$" + acc[1].getBalance());
System.out.println();
System.out.println("SAVINGS ACCOUNT");
acc[2] = new SavingsAccount(10, 50000);
System.out.println(acc[2].toString());
acc[2].deposit(10000);
System.out.println("Current balance after depositing is: " + "$" + acc[2].getBalance());
acc[2].addInterest();
}
}
I'm still new to this so I'm sorry if this is a bad question but I tried playing around with each class and I still can't figure out how to use the addInterest method I created in the SavingsAccount class that extends the Account class. I tried SavingsAccount.addInterest but I get a static reference error. I thought acc[2].addInterest would work but it says its undefined for the type Account.