Skip to content

Commit

Permalink
Feat: Added controller class that calculates status.
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyah committed Apr 9, 2026
1 parent 09d4664 commit f7b02c5
Showing 1 changed file with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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.
*
* <p>Calculates what status the player should get
* based on players' net worth compared to starting
* money, and current week.</p>
*
* @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;
}
}

0 comments on commit f7b02c5

Please sign in to comment.