Reputation: 1421
So I have a project due on saturday (I started last week saturday). The project is a sports prediction program.
I spent all of yesterday researching and getting all the information on the EPL (English Premier League) so I have all the results and fixtures in a database. As well as their current statistics (average goals per game, total wins, losses, league points, etc.)
I am currently comparing how many games they have won. What it does is retrieve data from the database from their 2 games over the season (they play 2 against every team, for those who don't watch soccer). It will either retrieve a "1" for a draw, or a name such as "Man Utd" for both games, or "Man Utd" and "Man City" for one game each.
How do I write the logic to predict which team is going to win on who won what? ie: Man Utd beat Man City and Man City beat Man utd, which is a 50-50 chance in the next game, but Man Utd beat Swansea twice, so Man Utd has a 90% chance of beating them in the next game.
Here is my code, which always comes out with a "50-50" so I dont know where I am going wrong.
This may be trivial, but not for me, please help as I am representing my school at a University where there will be scouts...
/**** get the result of the first game ****/
public String getGame1Result(String team1, String team2) throws SQLException{
String resultOfGame = null;
conn = DriverManager.getConnection(connection.conn_url, connection.conn_user, connection.conn_pass);
statement = conn.prepareStatement("SELECT games_winner, games_draw FROM games WHERE games_team1 = '" + team2 + "' AND games_team2 = '" + team1 + "'");
result = statement.executeQuery();
while(result.next()){
System.out.println(result.getString(1));
System.out.println(result.getString(2));
if(result.getString(1) == null){
resultOfGame = result.getString(2);
} else if(result.getString(2) == null) {
resultOfGame = result.getString(1);
} else {
resultOfGame = "Did not work";
}
}
return resultOfGame;
}
/**** get the result of the second game ****/
public String getGame2Result(String team1, String team2) throws SQLException{
String resultOfGame = null;
conn = DriverManager.getConnection(connection.conn_url, connection.conn_user, connection.conn_pass);
statement = conn.prepareStatement("SELECT games_winner, games_draw FROM games WHERE games_team1 = '" + team1 + "' AND games_team2 = '" + team2 + "'");
result = statement.executeQuery();
while(result.next()){
System.out.println(result.getString(1));
System.out.println(result.getString(2));
if(result.getString(1) == null){
resultOfGame = result.getString(2);
} else if(result.getString(2) == null) {
resultOfGame = result.getString(1);
} else {
resultOfGame = "Did not work";
}
}
return resultOfGame;
}
/**** compare the winner result ****/
private void compareGameWinnerResult(String game1Result, String game2Result, String team1, String team2) {
if((game1Result == "1") || (game2Result == "1")){ // checks for a draw
System.out.println("draw");
team1_winner_result = (float) 50;
team2_winner_result = (float) 50;
}
// } else if((game1Result.equals(team1)) && (game2Result.equals(team1))) { // checks for a winner of both games
// team1_winner_result = (float) 75;
// team2_winner_result = (float) 25;
// }
else if((game1Result.equals(team2)) && (game2Result.equals(team2))){ // checks for a winner of both games
team1_winner_result = (float) 25;
team2_winner_result = (float) 75;
} else if((game1Result.equals(team1) && (game2Result == null))){ // checks for a winner and a draw
team1_winner_result = (float) 75;
team2_winner_result = (float) 25;
} else if ((game1Result == null) && (game2Result.equals(team1))){ // checks for a winner and a draw
team1_winner_result = (float) 25;
team2_winner_result = (float) 75;
} else if((game1Result.equals(team2) && (game2Result == null))){ // checks for a winner and a draw
team1_winner_result = (float) 75;
team2_winner_result = (float) 25;
} else if ((game1Result == null) && (game2Result.equals(team2))){ // checks for a winner and a draw
team1_winner_result = (float) 25;
team2_winner_result = (float) 75;
}else { // last resort
team1_winner_result = (float) 50;
team2_winner_result = (float) 50;
}
System.out.println(team1 + " " + team1_winner_result);
System.out.println(team2 + " " + team2_winner_result);
}
Upvotes: 1
Views: 2225
Reputation: 12924
Change the below IF condition to use equals method,
if ((game1Result == "1") || (game2Result == "1"))
to
if ((game1Result.equals("1")) || (game2Result.equals("1")))
Upvotes: 1