帮忙 JAVA CODE Debuge

几分之几

新手上路
注册
2003-12-05
消息
2,968
荣誉分数
0
声望点数
0
应该是简单的错误,但不知道怎么改。

在chequingaccount里的withdraw(amount)应该怎么改才能对应bankacount里的public boolean withdraw(float anAmount)throws WithdrawException

不然会有错误出现(//mistake处):未报告的异常 WithdrawException;必须对其进行捕捉或声明以便抛出

这是bankaccount class


public abstract class BankAccount {
private static int LAST_ACCOUNT_NUMBER = 0;

protected int accountNumber;
protected String ownerName;
protected float balance;

private Loan storedLoan = null;
public BankAccount() { this("", 0); }
public BankAccount(String initName) { this(initName, 0); }
public BankAccount(String initName, float initBal) {
ownerName = initName;
accountNumber = ++LAST_ACCOUNT_NUMBER;
balance = initBal;
}


public int getAccountNumber() { return accountNumber; }
public String getOwnerName() { return ownerName; }
public float getBalance() { return balance; }
public void setOwnerName(String aName) {ownerName = aName; }
public String toString() {
return(ownerName + "'s " + this.getClass().getName()+ " Account #" + new java.text.DecimalFormat("000000").format(accountNumber) + " with " + new java.text.DecimalFormat("$0.00").format(balance));
}


public void deposit(float anAmount) {
balance += anAmount;
}

public void deposit(DepositableItem depositableItem) {
if(depositableItem instanceof Loan){
this.storedLoan = (Loan)depositableItem;
} else {
this.deposit(depositableItem.getAmount());
}
}

public void makeLoanPayment(float amount){
if(this.storedLoan != null){
if(this.storedLoan.interestAmount <= amount){
this.storedLoan.outstandingAmount -= (amount - this.storedLoan.interestAmount);
this.storedLoan.interestAmount = 0;
} else {
this.storedLoan.interestAmount -= amount;
}
}
}
public boolean withdraw(float anAmount)throws WithdrawException {
if (anAmount <= balance) {
balance -= anAmount;
return true;
}
return false;
}


public boolean writeCheque(float amount) {
if (amount <= balance) {
balance -= amount;
return true;
}
return false;
}

public void dailyProcess() {
if(this.storedLoan != null){
this.storedLoan.interestAmount += (Bank.LOAN_RATE/365.0f)*this.storedLoan.outstandingAmount;
}
}
public abstract void monthlyProcess();
}


这个是chequingaccount class



public class ChequingAccount extends BankAccount {
private int cheqCount;

public ChequingAccount(String ownerName) {
super(ownerName);
cheqCount = 0;
}

public boolean writeCheque(float amount) {
cheqCount++;
if(cheqCount<=3) {
return withdraw(amount); //mistake
}
else {
return withdraw(amount+1.25f); //mistake
}
}


public void monthlyProcess () {
cheqCount = 1;
}

}
 
public boolean writeCheque(float amount) {
cheqCount++;
if(cheqCount<=3) {
return withdraw(amount); //mistake
}
else {
return withdraw(amount+1.25f); //mistake


boolean is Data Type used to declare variables that can take one of the following values: TRUE, FALSE or NULL. Please note that "boolean" cannot be used as the datatype of a column.
 
代码:
	public boolean writeCheque(float amount) throws WithdrawException{
		chequeWrite++;
		if (!withdraw(amount + (chequeWrite > 3 ? 1.25f : 0.0f)))
		throw new WithdrawException("Insufficient funds");
			return true;
	}

..........
似乎是你们assignment4的作业,不是due了吗?
 
后退
顶部