私のドライバプログラムでは、この行は私にシンボルが見つかりませんでしたエラーです。なぜ、メソッドがSavingsAccountクラスで明確に定義され、私のドライバープログラムの他のすべてのメソッドには、それだけではなく、私はdouble型に変更しようとしましたが、それでもまだ動作しません。アカウントクラスから継承されます**を参照してください"シンボルを見つけることができません"メソッドが宣言されていますが、メソッドが宣言されています
Account acct2 = new SavingsAccount (name);
acct2.calculateBalance();
SavingsAccountクラス:
public class SavingsAccount extends Account
{
private final short minBalance = 0;
private double overdraftFee;
private double yearlyInterestRate = 0.02;
private double interestAmount;
public SavingsAccount (String name)
{
super(name);
}
public double withdraw (double amount)
{
if (accountBalance - amount >= minBalance)
{
accountBalance -= amount;
System.out.print ("Withdraw Successful");
}
else
{
accountBalance -= amount;
overdraftFee = accountBalance * (0.10);
accountBalance += overdraftFee;
System.out.print ("Withdraw Succesful, however overdraft fee of 10% has been applied to your account");
}
return accountBalance;
}
**public void calculateBalance()
{
interestAmount = (accountBalance * yearlyInterestRate);
accountBalance += interestAmount;
}**
public String toString()
{
return super.toString() + " Interest Received: " + interestAmount;
}
}
Accountクラス、必要に応じて
import java.util.Random;
import java.text.NumberFormat;
public abstract class Account
{
protected double accountBalance;
protected long accountNumber;
protected String accountHolder;
public Account (String name)
{
accountHolder = name;
accountBalance = 0;
Random accountNo = new Random();
accountNumber = accountNo.nextInt(100000);
}
public double deposit (double amount)
{
accountBalance += amount;
return accountBalance;
}
public String toString()
{
NumberFormat accountBal = NumberFormat.getCurrencyInstance();
return "Account Balance: " + accountBal.format(accountBalance) + "\nAccount Number: " + accountNumber;
}
public String getAccountHolder()
{
return accountHolder;
}
public double getAccountBalance()
{
return accountBalance;
}
public abstract double withdraw (double amount);
}
私はそれが抽象的 – Aaron
を行う能力を与えたと思いました私はコンセプトを完全にチェックしていませんでした – Abubakkar
推測ですが、あなたはAccount'クラス 'で' withdraw'メソッドを定義しているので、多型の参照が私にTHOS – Aaron