Skip to content

Commit

Permalink
Added status for player along with test
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikollai committed Apr 8, 2026
1 parent ce0dc04 commit a108919
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
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());
}
}

0 comments on commit a108919

Please sign in to comment.