From 03616e9e80d61666d3f393c7586ffb46f26ac468 Mon Sep 17 00:00:00 2001 From: = Date: Thu, 19 Mar 2026 08:07:00 +0100 Subject: [PATCH 1/5] Feat: Added playerstatus enum Did not implement logic for getting correct enum --- .../idi/idatt2003/g40/mappe/PlayerStatus.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/PlayerStatus.java diff --git a/src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/PlayerStatus.java b/src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/PlayerStatus.java new file mode 100644 index 0000000..a60a8ed --- /dev/null +++ b/src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/PlayerStatus.java @@ -0,0 +1,34 @@ +package edu.ntnu.idi.idatt2003.g40.mappe; + +/** + * Enum representing a players' current status. + * + *

The player has the responsibility for getting + * a status.

+ * */ +public enum PlayerStatus { + NOOB, + NOVICE, + GOOD, + TRYHARD, + PRO, + HACKER, + SEER, + OMNIPOTENT; + + /** + * Method for getting a player status based on a player. + * + *

Calculates what status the player should get + * based on players' net worth compared to starting + * money.

+ * + * @param player the player to give a status to. + * + * @return a PlayerStatus + * */ + public PlayerStatus getStatus(final Player player) { + return PlayerStatus.NOOB; + } +} + From 09d4664bef6c8f53031be2ad000b593ae4580128 Mon Sep 17 00:00:00 2001 From: = Date: Thu, 9 Apr 2026 15:35:44 +0200 Subject: [PATCH 2/5] Feat: Seperated constants and logic, removed from test folder --- .../idi/idatt2003/g40/mappe/PlayerStatus.java | 42 +++++++++++++++++++ .../idi/idatt2003/g40/mappe/PlayerStatus.java | 34 --------------- 2 files changed, 42 insertions(+), 34 deletions(-) create mode 100644 src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/PlayerStatus.java delete mode 100644 src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/PlayerStatus.java diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/PlayerStatus.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/PlayerStatus.java new file mode 100644 index 0000000..3bd959f --- /dev/null +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/PlayerStatus.java @@ -0,0 +1,42 @@ +package edu.ntnu.idi.idatt2003.g40.mappe; + +import java.math.BigDecimal; + +/** + * Enum representing a players' current status. + * + *

The player has the responsibility for getting + * a status.

+ * */ +public enum PlayerStatus { + + /** Status representing a beginner. */ + NOOB, + + /** + * Status representing a player who has increased + * their net worth by at least 20 percent. */ + NOVICE, + + /** + * Status representing a player who has increased + * their net worth by at least 50 percent. */ + GOOD, + + /** Status representing a player who has at least doubled their net worth. */ + TRYHARD, + + /** Status representing a player who has at least tripled their net worth. */ + PRO, + + /** + * Status representing a player who has at least quintupled their + * net worth. */ + SEER, + + /** + * Status representing a player who has at least dectupled their + * net worth. */ + OMNIPOTENT; +} + diff --git a/src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/PlayerStatus.java b/src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/PlayerStatus.java deleted file mode 100644 index a60a8ed..0000000 --- a/src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/PlayerStatus.java +++ /dev/null @@ -1,34 +0,0 @@ -package edu.ntnu.idi.idatt2003.g40.mappe; - -/** - * Enum representing a players' current status. - * - *

The player has the responsibility for getting - * a status.

- * */ -public enum PlayerStatus { - NOOB, - NOVICE, - GOOD, - TRYHARD, - PRO, - HACKER, - SEER, - OMNIPOTENT; - - /** - * Method for getting a player status based on a player. - * - *

Calculates what status the player should get - * based on players' net worth compared to starting - * money.

- * - * @param player the player to give a status to. - * - * @return a PlayerStatus - * */ - public PlayerStatus getStatus(final Player player) { - return PlayerStatus.NOOB; - } -} - From f7b02c5389ab87107fdcdd3cb3213a862af28170 Mon Sep 17 00:00:00 2001 From: = Date: Thu, 9 Apr 2026 15:37:17 +0200 Subject: [PATCH 3/5] Feat: Added controller class that calculates status. --- .../g40/mappe/PlayerStatusController.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/PlayerStatusController.java diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/PlayerStatusController.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/PlayerStatusController.java new file mode 100644 index 0000000..459ee73 --- /dev/null +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/PlayerStatusController.java @@ -0,0 +1,54 @@ +package edu.ntnu.idi.idatt2003.g40.mappe; + +import java.math.BigDecimal; + +/** + * Controls and calculates the players' status. + * + * @see PlayerStatus + * */ +public final class PlayerStatusController { + private PlayerStatusController() { + /* This utility class should not be instantiated */ + } + + /** + * Method for getting a player status based on a player. + * + *

Calculates what status the player should get + * based on players' net worth compared to starting + * money, and current week.

+ * + * @param player the player to give a status to. + * + * @return a PlayerStatus + * */ + public static PlayerStatus getStatus(final Player player) { + Integer startingMoneyInt = player.getStartingMoney().intValue(); + + BigDecimal difference = + player.getNetWorth().subtract(player.getStartingMoney()); + + return switch ((Integer) difference.intValue()) { + case Integer val when val >= percentAmount(startingMoneyInt, 900) -> PlayerStatus.OMNIPOTENT; + case Integer val when val >= percentAmount(startingMoneyInt, 400) -> PlayerStatus.SEER; + case Integer val when val >= percentAmount(startingMoneyInt, 200) -> PlayerStatus.PRO; + case Integer val when val >= percentAmount(startingMoneyInt, 100) -> PlayerStatus.TRYHARD; + case Integer val when val >= percentAmount(startingMoneyInt, 50) -> PlayerStatus.GOOD; + case Integer val when val >= percentAmount(startingMoneyInt, 20) -> PlayerStatus.NOVICE; + default -> PlayerStatus.NOOB; + }; + } + + /** + * Helper method for increasing a value by x percent. + * + * @param value the value to calculate from + * @param x the percent amount + * + * @return the increased value. + * */ + private static Integer percentAmount(final Integer value, final Integer x) { + return (value * x) / 100; + } +} From 25e96a78eb8fe35b9a690d4e6a6e98630c81bf08 Mon Sep 17 00:00:00 2001 From: = Date: Thu, 9 Apr 2026 15:37:30 +0200 Subject: [PATCH 4/5] Feat: GetStartingMoney() method in player --- .../java/edu/ntnu/idi/idatt2003/g40/mappe/Player.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Player.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Player.java index 9186f09..fa933b9 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Player.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Player.java @@ -64,6 +64,15 @@ public String getName() { return name; } + /** + * Returns the players chosen starting balance. + * + * @return the starting money the player chose. + */ + public BigDecimal getStartingMoney() { + return startingMoney; + } + /** * Returns the players current balance. * From 08bd55bc8c74463677cf609398261c6c59cd51fd Mon Sep 17 00:00:00 2001 From: = Date: Thu, 9 Apr 2026 15:37:42 +0200 Subject: [PATCH 5/5] Feat: Testing player status calculations --- .../idatt2003/g40/mappe/PlayerStatusTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/PlayerStatusTest.java diff --git a/src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/PlayerStatusTest.java b/src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/PlayerStatusTest.java new file mode 100644 index 0000000..b038bb5 --- /dev/null +++ b/src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/PlayerStatusTest.java @@ -0,0 +1,22 @@ +package edu.ntnu.idi.idatt2003.g40.mappe; + +import org.junit.jupiter.api.Test; + +import java.math.BigDecimal; + +import static org.junit.jupiter.api.Assertions.*; + +class PlayerStatusTest { + + @Test + void getStatusReturnsProperStatuses() { + Player testPlayer = new Player("Player", new BigDecimal(1000)); + PlayerStatus gottenStatus = PlayerStatusController.getStatus(testPlayer); + assertEquals(PlayerStatus.NOOB, gottenStatus); + + testPlayer.addMoney(new BigDecimal(1000)); + PlayerStatus gottenStatus2 = PlayerStatusController.getStatus(testPlayer); + + assertEquals(PlayerStatus.TRYHARD, gottenStatus2); + } +} \ No newline at end of file