1

当座預金口座と普通預金口座から資金を送金できる銀行口座が必要な任務があります。トランザクションは 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");
        }
    }
4

1 に答える 1

4

コンストラクターには戻り値の型がありません。そうではない

// this is a "pseudo"-constructor
public void TransferService(){

むしろ

// this is the real deal
public TransferService(){

それにかんする、

トランザクションは抽象的で、インスタンス化できません

そうですね?Transaction クラスは抽象クラスですか、それともインターフェースですか? これに対する答えは、コードを持っているあなただけが知っています。これが当てはまる場合は、コードで Transaction の具体的な実装を使用する必要があります。

于 2014-11-02T00:42:01.997 に答える