From f98702ee51f7f539ffe7de4cc224816c12726577 Mon Sep 17 00:00:00 2001 From: EspenTinius Date: Thu, 19 Feb 2026 23:39:10 +0100 Subject: [PATCH 1/2] Transactions class methods javadoc will be next --- .../g40/mappe/TransactionArchive.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/TransactionArchive.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/TransactionArchive.java index e69de29..5b816b5 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/TransactionArchive.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/TransactionArchive.java @@ -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 transactions = new ArrayList<>(); + + public TransactionArchive() { + } + + public boolean add(Transaction transaction) { + return transactions.add(transaction); + } + + public boolean isEmpty() { + return transactions.isEmpty(); + } + + public List getTransactions(int week) { + List result = new ArrayList<>(); + for (Transaction transaction : transactions) { + if (transaction.getWeek() == week) { + result.add(transaction); + } + } + return result; + } + + public List getPurchases(int week) { + List result = new ArrayList<>(); + for (Transaction transaction : transactions) { + if (transaction instanceof Purchase purchase && transaction.getWeek() == week) { + result.add(purchase); + } + } + return result; + } + + public List getSales(int week) { + List result = new ArrayList<>(); + for (Transaction transaction : transactions) { + if (transaction instanceof Sale sale && transaction.getWeek() == week) { + result.add(sale); + } + } + return result; + } + + public int countDistinctWeeks() { + List weeks = new ArrayList<>(); + for (Transaction transaction : transactions) { + int week = transaction.getWeek(); + if (!weeks.contains(week)) { + weeks.add(week); + } + } + return weeks.size(); + } +} \ No newline at end of file From 445c753f60e3c8f844a98f2aa3c3a59504185a0c Mon Sep 17 00:00:00 2001 From: EspenTinius Date: Thu, 19 Feb 2026 23:48:02 +0100 Subject: [PATCH 2/2] TransactionsArchive class doc javadoc --- .../g40/mappe/TransactionArchive.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/TransactionArchive.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/TransactionArchive.java index 5b816b5..c09cec6 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/TransactionArchive.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/TransactionArchive.java @@ -3,21 +3,44 @@ import java.util.ArrayList; import java.util.List; +/** + * Stores completed transactions. + */ public class TransactionArchive { private final List transactions = new ArrayList<>(); + /** + * Creates an empty transaction archive. + */ public TransactionArchive() { } + /** + * Adds a transaction to the archive. + * + * @param transaction the transaction to add + * @return true if the transaction was added + */ public boolean add(Transaction transaction) { return transactions.add(transaction); } + /** + * Checks whether the archive is empty. + * + * @return true if no transactions exist + */ public boolean isEmpty() { return transactions.isEmpty(); } + /** + * Returns all transactions from a given week. + * + * @param week the week number + * @return list of transactions from the given week + */ public List getTransactions(int week) { List result = new ArrayList<>(); for (Transaction transaction : transactions) { @@ -28,6 +51,12 @@ public List getTransactions(int week) { return result; } + /** + * Returns all purchase transactions from a given week. + * + * @param week the week number + * @return list of purchases from the given week + */ public List getPurchases(int week) { List result = new ArrayList<>(); for (Transaction transaction : transactions) { @@ -38,6 +67,12 @@ public List getPurchases(int week) { return result; } + /** + * Returns all sale transactions from a given week. + * + * @param week the week number + * @return list of sales from the given week + */ public List getSales(int week) { List result = new ArrayList<>(); for (Transaction transaction : transactions) { @@ -48,6 +83,11 @@ public List getSales(int week) { return result; } + /** + * Counts the number of distinct weeks with transactions. + * + * @return number of distinct weeks + */ public int countDistinctWeeks() { List weeks = new ArrayList<>(); for (Transaction transaction : transactions) {