From e422eee0a8aa518c77ab0a9ecf2332599f682390 Mon Sep 17 00:00:00 2001 From: = Date: Tue, 3 Mar 2026 13:17:09 +0100 Subject: [PATCH 1/3] Feat: Updated Transaction class to have proper attributes and methods --- .../java/edu/ntnu/idi/idatt2003/g40/mappe/Transaction.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Transaction.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Transaction.java index 4030335..78156de 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Transaction.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Transaction.java @@ -12,7 +12,7 @@ public abstract class Transaction { private final TransactionCalculator calculator; - private boolean commited = false; + protected boolean commited = false; /** * Creates a new {@code Transaction} with a share, week and calculator. @@ -62,7 +62,5 @@ public boolean isCommited() { } /** Commits the transaction. */ - public void commit() { - commited = true; - } + public abstract void commit(Player player); } From c4bd20bf1921dd8258ae4c43e38232d8520ebbc3 Mon Sep 17 00:00:00 2001 From: = Date: Tue, 3 Mar 2026 13:17:32 +0100 Subject: [PATCH 2/3] Feat: Added purchase class (commit method not fully implemented) --- .../idi/idatt2003/g40/mappe/Purchase.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Purchase.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Purchase.java index e69de29..717c73c 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Purchase.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Purchase.java @@ -0,0 +1,31 @@ +package edu.ntnu.idi.idatt2003.g40.mappe; + +/** + * Purchase represents purchases the player commits. + * + *

Extends {@link Transaction}

+ * + * */ +public class Purchase extends Transaction { + + /** + * Constructor. + * + * @param share the {@link Share} object to purchase. + * @param week the week to purchase during. + * @param calculator the {@link TransactionCalculator} object to calculate this purchase. + * */ + public Purchase(final Share share, final int week, final TransactionCalculator calculator) { + super(share, week, calculator); + } + + /** + * Commits the purchase. + * + * @param player the {@link Player} object performing the purchase. + * */ + @Override + public void commit(final Player player) { + commited = true; + } +} From a5e46be03ae3344503ee35a56591f833d41b4707 Mon Sep 17 00:00:00 2001 From: = Date: Tue, 3 Mar 2026 13:19:08 +0100 Subject: [PATCH 3/3] Feat: Added unit testing for Purchase class --- .../idi/idatt2003/g40/mappe/PurchaseTest.java | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/PurchaseTest.java b/src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/PurchaseTest.java index e24f0aa..33174da 100644 --- a/src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/PurchaseTest.java +++ b/src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/PurchaseTest.java @@ -1,3 +1,36 @@ -public class PurchaseTest { - +package edu.ntnu.idi.idatt2003.g40.mappe; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.math.BigDecimal; +import org.junit.jupiter.api.Test; + +/** + * Test class for {@link Purchase}. + * */ +class PurchaseTest { + + Stock testStock = new Stock("AAPL", "Apple Inc.", new BigDecimal("100.00")); + Share testShare = new Share(testStock, new BigDecimal("10"), new BigDecimal("10")); + PurchaseCalculator testPurchaseCalculator = new PurchaseCalculator(testShare); + Player testPlayer = new Player("TestName", new BigDecimal("1000.00")); + + @Test + void constructor_sets_values() { + Purchase purchase = new Purchase(testShare, 1, testPurchaseCalculator); + + assertEquals(testShare, purchase.getShare()); + assertEquals(1, purchase.getWeek()); + assertEquals(testPurchaseCalculator, purchase.getCalculator()); + } + + @Test + void commit_method_sets_commit_to_true() { + Purchase purchase = new Purchase(testShare, 1, testPurchaseCalculator); + + purchase.commit(testPlayer); + + assertTrue(purchase.isCommited()); + } }