我在尝试根据此要求编译以下代码时遇到问题:
给定一个现有类 BankAccount,其中包含: 一个构造函数,接受对应于帐户持有人姓名的字符串。一个方法,getBalance,它返回对应于帐户余额的双精度值。一种接受双倍的取款方法,并从账户余额中扣除金额。为子类 CheckingAccount 编写一个类定义,其中包含:一个布尔实例变量,透支。(为支票账户透支允许开出大于当前余额的支票)。一个接受字符串和布尔值的构造函数。String 参数用于调用超类(BankAccount)构造函数,而布尔值用于初始化透支实例变量。一个方法,hasOverdraft,它返回一个布尔值。如果帐户支持透支,hasOverdraft 返回 true。一个方法,clearCheck,它接受一个双精度并返回一个布尔值。clearCheck 将确定(支票的)金额是否可以兑现——如果金额小于账户余额,或者账户允许透支,就会出现这种情况。如果支票可以兑现,则clearCheck返回true,同时调用withdraw方法更新账户余额;否则,clearCheck 返回 false。
代码:
public class CheckingAccount extends BankAccount {
private boolean overdraft;
public CheckingAccount(String a, boolean overdraft) {
this.name = super.name;
this.overdraft = overdraft;}
boolean hasOverdraft() {if(overdraft); return true;}
boolean clearCheck(double checkAmount) {if(checkAmount < balance || hasOverdraft() == true); return true && withdraw();}
}
错误:
CheckingAccount.java:4: error: constructor BankAccount in class BankAccount cannot be applied to given types;
public CheckingAccount(String a, boolean overdraft) {
^
required: String
found: no arguments
reason: actual and formal argument lists differ in length
CheckingAccount.java:5: error: name has private access in BankAccount
this.name = super.name;
^
CheckingAccount.java:5: error: name has private access in BankAccount
this.name = super.name;
^
CheckingAccount.java:10: error: method withdraw in class BankAccount cannot be applied to given types;
boolean clearCheck(double checkAmount) {if(checkAmount < balance || hasOverdraft() == true); return true && withdraw();}