diff --git a/Common/src/main/java/edu/sdccd/cisc191/template/Bet.java b/Common/src/main/java/edu/sdccd/cisc191/template/Bet.java index 6bb12148..19910e11 100644 --- a/Common/src/main/java/edu/sdccd/cisc191/template/Bet.java +++ b/Common/src/main/java/edu/sdccd/cisc191/template/Bet.java @@ -29,7 +29,6 @@ public class Bet { private final double[][] winOddsOvertime = new double[numHours][2]; // Array to track odds over time private boolean fulfillment; - private final long currentEpochSeconds = System.currentTimeMillis() / 1000; // Current time in seconds @JsonIgnore private static final ObjectMapper objectMapper = new ObjectMapper(); @@ -42,6 +41,7 @@ public class Bet { * @throws Exception If serialization fails. */ public static String toJSON(Bet bet) throws Exception { + // TODO: Improve exception handling - catch JsonProcessingException specifically return objectMapper.writeValueAsString(bet); } @@ -80,6 +80,7 @@ public Bet(Game g, int amt, String betTeam) { this.betTeam = betTeam; this.betAmt = amt; + // TODO: Use an Enum instead of Strings for teams if (betTeam.equalsIgnoreCase("team1")) { winOdds = (int) Game.getTeam1Odd(); } else if (betTeam.equalsIgnoreCase("team2")) { @@ -94,6 +95,9 @@ public Bet(Game g, int amt, String betTeam) { // Populate winOddsOvertime with odds and timestamps for (int j = 0; j < numHours; j++) { + // Current time in seconds + // Moved to be a local variable + long currentEpochSeconds = System.currentTimeMillis() / 1000; long timeStamp = currentEpochSeconds - (j * 3600L); // Decrement by hours double odd = calculateOddsForGameAtTime(timeStamp); winOddsOvertime[j][0] = odd; @@ -109,6 +113,7 @@ public Bet(Game g, int amt, String betTeam) { */ private double calculateOddsForGameAtTime(long timeStamp) { return 1 + random.nextInt(100); // Generate a random value between 1 and 100 + // TODO: Replace with real odds calculations using an API for architect assignment 2 } /** @@ -169,15 +174,13 @@ public double[][] getWinOddsOvertime() { * Updates the user's money based on the outcome of the bet. * * @param user The user associated with the bet. - * @return The updated user object. */ - public User updateUser(User user) { + public void updateUser(User user) { if (fulfillment) { user.setMoney(user.getMoney() + winAmt); } else { user.setMoney(user.getMoney() - winAmt); } - return user; } /** @@ -228,7 +231,9 @@ public void setBetAmt(int betAmt) { * @return A string describing the bet. */ @Override + public String toString() { + // TODO: Improve output format to show team name, bet amount, and odds return "Bet on " + game + " for " + betAmt; } } diff --git a/Common/src/main/java/edu/sdccd/cisc191/template/Game.java b/Common/src/main/java/edu/sdccd/cisc191/template/Game.java index 37f33809..439574e2 100644 --- a/Common/src/main/java/edu/sdccd/cisc191/template/Game.java +++ b/Common/src/main/java/edu/sdccd/cisc191/template/Game.java @@ -82,8 +82,8 @@ public Game(String t1, String t2, Date startDate, Date endDate) { this.startDate = startDate; this.endDate = endDate; - this.team1Odd = Math.round(Math.random() * 100); - this.team2Odd = Math.round(Math.random() * 100); + team1Odd = Math.round(Math.random() * 100); + team2Odd = Math.round(Math.random() * 100); this.dateClean = this.getDateClean(); } /** @@ -119,6 +119,8 @@ public Game(String t1, String t2, Date startDate, Date endDate, double team1Odd, * @param team1Odd The odds for team 1. * @param team2Odd The odds for team 2. */ + + //TODO: These parameters are never used public Game(String t1, String t2, Date startDate, Date endDate, double team1Odd, double team2Odd, double pool) { this.team1Wager = 80; this.team2Wager = 20; @@ -151,6 +153,7 @@ public Game(String t1, String t2, Date startDate, Date endDate, double team1Odd, */ @Override public String toString() { + // TODO: Format output better using DateFormat instead of manual date calculations return team1 + " vs. " + team2 + " on " + startDate.getMonth() + "/" + startDate.getDate() + "/" + (startDate.getYear() + 1900); } @@ -176,8 +179,8 @@ public boolean equals(Object obj) { boolean team2Equals = Objects.equals(this.team2, game.getTeam2()); boolean startDateEquals = this.startDate.compareTo(game.getStartDate()) == 0; boolean endDateEquals = this.endDate.compareTo(game.getEndDate()) == 0; - boolean team1OddEquals = Math.abs(this.team1Odd - game.getTeam1Odd()) < 0.0001; - boolean team2OddEquals = Math.abs(this.team2Odd - game.getTeam2Odd()) < 0.0001; + boolean team1OddEquals = Math.abs(team1Odd - getTeam1Odd()) < 0.0001; + boolean team2OddEquals = Math.abs(team2Odd - getTeam2Odd()) < 0.0001; return team1Equals && team2Equals && startDateEquals && endDateEquals && team1OddEquals && team2OddEquals; } @@ -244,6 +247,7 @@ public Date getEndDate() { * @return A string describing the start and end dates. */ public String getDateClean() { + // TODO: Use SimpleDateFormat instead of manually adjusting Java Date fields return (startDate.getMonth() + 1) + "/" + startDate.getDate() + "/" + (startDate.getYear() + 1900) + " - " + (endDate.getMonth() + 1) + "/" + endDate.getDate() + "/" + (endDate.getYear() + 1900); }