我有一项作业,要求银行帐户能够从支票和储蓄帐户转移资金。交易存储在 ArrayList 中,并由用户指定何时转移资金。用于支票和储蓄的银行帐户类工作正常,但我创建的 TransferService 类在 NetBeans 中无法正确编译。
这些提示似乎并没有修复错误。我收到错误:
事务是抽象的,无法实例化。
我该如何解决这个问题?
import java.util.ArrayList;
import java.util.Date;
import javax.transaction.Transaction;
public class TransferService {
private Date currentDate;
private ArrayList<Transaction> completedTransactions;
private ArrayList<Transaction> pendingTransactions;
public void TransferService(){
this.currentDate = new Date();
this.completedTransactions = new ArrayList<Transaction>();
this.pendingTransactions = new ArrayList<Transaction>();
}
public TransferService(BankAccount to, BankAccount from, double amount, Date when) throws InsufficientFundsException(){
if (currentDate.after(when)){
try(
from.withdrawal(amount);
to.deposit(amount);
completedTransactions.add(new Transaction(to, from, this.currentDate, Transaction.TransactionStatus.COMPLETE));
} catch (InsufficientFundsException ex){
throw ex;
}
} else {
pendingTransactions.add(new Transaction(to, from, null, Transaction.TransactionStatus.PENDING));
}
}
private static class InsufficientFundsException extends Exception {
public InsufficientFundsException() {
System.out.println("Insufficient funds for transaction");
}
}
构造函数没有返回类型。所以不
// this is a "pseudo"-constructor
public void TransferService(){
反而
// this is the real deal
public TransferService(){
关于,
事务是抽象的,无法实例化
嗯,是吗? Transaction类是抽象类还是接口?只有拥有代码的你才知道这个问题的答案。如果这是真的,那么您将需要在代码中使用 Transaction 的具体实现。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)