此處的新手總數(感謝承擔)。我創建了一個抽象父類:超級抽象類未被接受的子類參數父類
public abstract class Account {
public double setInterestRate (double interestRate) {
return this. interestRate = interestRate/100;
public abstract void withdraw(double amount);
public void deposit(double amount) {
if (amount < 0) { // amount is invalid: exception occurs
throw new IllegalArgumentException("Error: Deposit cannot be a"
+ " negative value.");
} else {
this.deposit = amount;
balance = balance + amount;
}
}
public void calculateBalance() {
double interestTotal = balance * setInterestRate(interestRate);
this.balance = balance + interestTotal;
}
public double annualEarnings (double interest) {
return this.interest = 1000 * setInterestRate(interestRate);
}
在子類中我想的annualInterest變量作爲參數傳遞給super.annualEarnings(annualInterest)方法我在的toString()調用:
public class CheckingAccount extends Account implements Overdraftable {
protected double annualInterest = 1.0;
@Override
public String toString() {
return super.toString() + "\n"+ account + "\t\t" + deposit + "\t\t"
+ withdrawAmt +"\t\t" + super.annualEarnings(annualInterest)+ "\t\t" + super.balance ;
}
我希望這種類型的打印出來:
=======================================
AccNo. Deposit Withdraw Intr. NewBal
=======================================
101 200.00 0.00 10.00 1210.00
凡INIT每年1000美元的簡單利息是10美元(又稱10.00英鎊),剩下的只是200美元的存款,加上1000美元的初始金額以及NewBal的10美元利息。
那麼你可以說,什麼是實際輸出/錯誤,你所看到的,也是類的完整結構將有助於 –
@AkashYadav剛剛添加的全很多 - 謝謝隊友! –
仍然需要很多工作才能實現。請看看這個https://en.wikipedia.org/wiki/Minimal_Working_Example –