-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTransactionService.java
More file actions
40 lines (37 loc) · 1.21 KB
/
TransactionService.java
File metadata and controls
40 lines (37 loc) · 1.21 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
package Bank;
import java.util.*;
public class TransactionService {
private List<Transaction> transactions = new ArrayList<>();
public void recordTransaction(String accountNumber, double amount, String type)
{
transactions.add(new Transaction(accountNumber, amount, type));
}
public List<Transaction> getTransactionsByAccount(String accNo)
{
List<Transaction> result = new ArrayList<>();
for (Transaction t : transactions)
{
if (t.getAccno().equals(accNo))
{
result.add(t);
}
}
return result;
}
public void printTransactions(String accNo)
{
List<Transaction> txns = getTransactionsByAccount(accNo);
if (txns.isEmpty())
{
System.out.println("No transactions found for account: " + accNo);
}
else
{
for (Transaction t : txns)
{
long randomNum = (long) (Math.random() * 10000000);
System.out.println("[" + t.getTimestamp() + "] " + "\nTask Performed : " + t.getType() + "\nMoney : " + t.getAmount() + "\nID : " + randomNum + "\n----------------------");
}
}
}
}