-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
javadoc will be next
- Loading branch information
EspenTinius
committed
Feb 19, 2026
1 parent
f3e7f30
commit f98702e
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package edu.ntnu.idi.idatt2003.g40.mappe; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class TransactionArchive { | ||
|
|
||
| private final List<Transaction> transactions = new ArrayList<>(); | ||
|
|
||
| public TransactionArchive() { | ||
| } | ||
|
|
||
| public boolean add(Transaction transaction) { | ||
| return transactions.add(transaction); | ||
| } | ||
|
|
||
| public boolean isEmpty() { | ||
| return transactions.isEmpty(); | ||
| } | ||
|
|
||
| public List<Transaction> getTransactions(int week) { | ||
| List<Transaction> result = new ArrayList<>(); | ||
| for (Transaction transaction : transactions) { | ||
| if (transaction.getWeek() == week) { | ||
| result.add(transaction); | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| public List<Purchase> getPurchases(int week) { | ||
| List<Purchase> result = new ArrayList<>(); | ||
| for (Transaction transaction : transactions) { | ||
| if (transaction instanceof Purchase purchase && transaction.getWeek() == week) { | ||
| result.add(purchase); | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| public List<Sale> getSales(int week) { | ||
| List<Sale> result = new ArrayList<>(); | ||
| for (Transaction transaction : transactions) { | ||
| if (transaction instanceof Sale sale && transaction.getWeek() == week) { | ||
| result.add(sale); | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| public int countDistinctWeeks() { | ||
| List<Integer> weeks = new ArrayList<>(); | ||
| for (Transaction transaction : transactions) { | ||
| int week = transaction.getWeek(); | ||
| if (!weeks.contains(week)) { | ||
| weeks.add(week); | ||
| } | ||
| } | ||
| return weeks.size(); | ||
| } | ||
| } |