小编MrL*_*l81的帖子

为什么我的 public void Constructor {} 无法编译?

我有一项作业,要求银行帐户能够从支票和储蓄帐户转移资金。交易存储在 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, …
Run Code Online (Sandbox Code Playgroud)

java constructor compiler-errors banking

2
推荐指数
1
解决办法
490
查看次数

标签 统计

banking ×1

compiler-errors ×1

constructor ×1

java ×1