我需要编写一个抽象的BankAccount类和一个可扩展BankAccount的SavingsAccount类。我花了很多钱,但在底部super.monthlyProcess();附近的行上却一直找不到符号错误。我该如何解决?我到底要在哪里宣布呢?当我运行BankAccount类时,效果很好。
public abstract class BankAccount{
//declares the class variables
private double balance;
private int num_deposits;
private int num_withdraws;
private double annualInterest;
private double serviceCharges;
//Constructor with two arguments to initialize the balance and the annual interest rate
public BankAccount(double balance, double annualInterest){
this.balance=balance;
this.annualInterest=annualInterest;
this.num_deposits=0;
this.num_withdraws=0;
this.serviceCharges=0;
}
//Method for deposits into the BankAccount
public void deposit(double amount){
balance+=amount;
num_deposits++;
}
//Method for withdrawals from the BankAccount
public void withdraw(double amount){
balance-=amount;
num_withdraws++;
}
//Method to calculate the monthly interest
public void calcInterest(){
double monthlyInterestRate=(annualInterest/12);
double monthlyInterest= this.balance*monthlyInterestRate;
balance+=monthlyInterest;
}
//Method that deducts the monthly service charge and updates the balance
public void monthlyProccess(){
balance-=serviceCharges;
calcInterest();
num_deposits=0;
num_withdraws=0;
serviceCharges=0;
}
//Getter and Setter for balance method
public double getBalance(){
return balance;
}
public void setBalance(double balance){
this.balance=balance;
}
//Getter and Setter for number of deposits
public int getNum_deposits(){
return num_deposits;
}
public void setNum_deposits(int num_deposits){
this.num_deposits=num_deposits;
}
//Getter and Setter for number of withdrawals
public int getNum_withdraws(){
return num_withdraws;
}
public void setNum_withdraws(int num_withdraws){
this.num_withdraws=num_withdraws;
}
//Getter and Setter for the Annual Interest
public double getAnnualInterest(){
return annualInterest;
}
public void setAnnualInterest(double annualInterest){
this.annualInterest=annualInterest;
}
//Getter and Setter for the monthly service charges
public double getServiceCharges(){
return serviceCharges;
}
public void setServiceCharges(double serviceCharges){
this.serviceCharges=serviceCharges;
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------
public class SavingsAccount extends BankAccount{
private boolean status;
public SavingsAccount(double balance, double annualInterest){
//Initialize superclass constructor
super(balance, annualInterest);
//Set the active status to true or false
if(balance>=25){
status=true;
}
else{
status=false;
}
}
//withdraw() method to check if the account is active or inactive
public void withdraw(double amount){
if(status){
super.withdraw(amount);
if(super.getBalance()<25)
status=false;
}
else{
System.out.println("Amount cannot be withdrawn.");
}
}
//deposit() method to check if the account in active or inactive
public void deposit(double amount){
if(!status){
double avail=super.getBalance()+amount;
if(avail>=25){
status=true;
}
}
super.deposit(amount);
}
//monthlyProcess() checks and sets a $1 service charge for withdraws and deposits greater than 4.
public void monthlyProcess(){
int countWithdraws=super.getNum_withdraws();
if(countWithdraws>4){
super.setServiceCharges(countWithdraws-4);
super.monthlyProcess();
if(super.getBalance()<25)
status=false;
}
}
//Getter and Setter for the status
public boolean isStatus(){
return status;
}
public void setStatus(boolean status){
this.status=status;
}