所以我有一个星期六要交的项目(我上周星期六开始的)。该项目是一个体育预测程序。
昨天我花了所有时间研究和获取有关 EPL(英超联赛)的所有信息,因此我将所有结果和赛程都保存在数据库中。以及他们目前的统计数据(每场比赛的平均进球数、总胜负数、联赛积分等)
我目前正在比较他们赢了多少场比赛。它所做的是从数据库中检索他们本赛季 2 场比赛的数据(他们与每支球队比赛 2 场,对于那些不看足球的人)。它将为平局检索一个“1”,或者为两场比赛检索一个名称,例如“Man Utd”,或者为一场比赛检索“Man Utd”和“Man City”。
我如何编写逻辑来预测哪支球队会赢谁赢了什么?即:曼联击败曼城,曼城击败曼联,下一场比赛有50-50的机会,但曼联两次击败斯旺西,所以曼联有90%的机会在下一场比赛中击败他们。
这是我的代码,它总是带有“50-50”,所以我不知道我哪里出错了。
这可能是微不足道的,但对我来说不是,请帮忙,因为我代表我的学校在一所大学,那里会有童子军......
/**** 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);
}