Java构造函数没有正确编译

我是Java的新手,最近刚开始上课,所以仍然掌握一切是如何运作的,所以请在我尝试理解所有这些新材料时请耐心等待。

我的任务要求银行账户能够从支票和储蓄账户转账。 交易存储在arraylist中并为用户设置以指定何时转移资金。 用于检查和保存的银行帐户类工作正常但我创建的transferervice类在我正在使用的ide netbeans中没有正确编译。

我的教师重写了我的一些代码以帮助但它仍然无法编译,提示似乎没有修复错误。 我得到的Transaction是抽象的,无法实例化。 我不太清楚我能做些什么来解决这个错误,所以任何帮助都会非常感激。

import java.util.ArrayList; import java.util.Date; import javax.transaction.Transaction; public class TransferService { private Date currentDate; private ArrayList completedTransactions; private ArrayList pendingTransactions; public void TransferService(){ this.currentDate = new Date(); this.completedTransactions = new ArrayList(); this.pendingTransactions = new ArrayList(); } 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的具体实现。