-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseTransaction.java
More file actions
50 lines (41 loc) · 1.38 KB
/
Copy pathBaseTransaction.java
File metadata and controls
50 lines (41 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.transactions.transactions;
import com.transactions.exceptions.InsufficientFundsException;
import com.transactions.interfaces.TransactionInterface;
import com.transactions.models.BankAccount;
import java.util.Calendar;
import java.util.UUID;
public class BaseTransaction implements TransactionInterface {
private double amount;
private Calendar date;
private String transactionID;
public BaseTransaction(double amount, Calendar date) {
this.amount = amount;
this.date = date;
this.transactionID = UUID.randomUUID().toString();
}
@Override
public double getAmount() {
return amount;
}
@Override
public Calendar getDate() {
return date;
}
@Override
public String getTransactionID() {
return transactionID;
}
@Override
public void printTransactionDetails() {
System.out.println("Transaction ID: " + transactionID);
System.out.println("Amount: " + amount);
System.out.println("Date: " + date.getTime());
}
// Base apply method - does not perform any actual credit or debit
// subclasses override this with their own specific behaviour
@Override
public void apply(BankAccount ba) throws InsufficientFundsException {
System.out.println("Applying base transaction to: " + ba.getAccountHolder());
printTransactionDetails();
}
}