Skip to content
Open
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
13 changes: 9 additions & 4 deletions Common/src/main/java/edu/sdccd/cisc191/template/Bet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}

Expand Down Expand Up @@ -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")) {
Expand All @@ -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;
Expand All @@ -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
}

/**
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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;
}
}
12 changes: 8 additions & 4 deletions Common/src/main/java/edu/sdccd/cisc191/template/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
/**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down