I have an assignment that requires a bank account to be able to transfer funds from a checking and savings account. The transactions are stored in an ArrayList and set up for the user to specify when to transfer the funds. The bank account class for checking and savings works OK, but the TransferService class I created isn't compiling properly in NetBeans.
The hints don't seem to be fixing the errors. I get the error:
Transaction is abstract and cannot be instantiated.
How can I fix this problem?
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");
}
}