Skip to content

Added status for player skill #30

Merged
merged 1 commit into from
Apr 8, 2026
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/main/java/millions/Player.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package millions;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class Player {
private String name;
private BigDecimal startingMoney;
private BigDecimal money;
private Portfolio portfolio;
private TransactionArchive transactionArchive;
//temporary attribute until a better solution is found
public int weeksTraded;

public Player(String name, BigDecimal startingMoney) {
this.name = name;
Expand Down Expand Up @@ -45,6 +48,19 @@ public BigDecimal getNetWorth() {
return netWorth;
}

public String getStatus() {
String status = "Novice";
BigDecimal netWorth = getNetWorth();
BigDecimal netWorthChange = netWorth.divide(startingMoney, RoundingMode.DOWN);
if (netWorthChange.compareTo(BigDecimal.valueOf(0.20)) >= 0 && weeksTraded >= 10) {
status = "Investor";
}
if (netWorthChange.compareTo(BigDecimal.valueOf(0.40)) >= 0 && weeksTraded >= 20) {
status = "Speculator";
}
return status;
}

public String getName() {
return this.name;
}
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/millions/PlayerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,22 @@ public void testNullsAndInvalid() {
assertThrows(IllegalArgumentException.class, () -> new Player("name", null));
assertThrows(IllegalArgumentException.class, () -> new Player("name", BigDecimal.valueOf(-1)));
}

@Test
public void testStatus() {
Player player = new Player("name", BigDecimal.valueOf(1000));
assertEquals("Novice", player.getStatus());

player.addMoney(BigDecimal.valueOf(200));
assertEquals("Novice", player.getStatus());

player.weeksTraded = 10;
assertEquals("Investor", player.getStatus());

player.addMoney(BigDecimal.valueOf(200));
assertEquals("Investor", player.getStatus());

player.weeksTraded = 20;
assertEquals("Speculator", player.getStatus());
}
}