【发布时间】:2017-10-28 10:36:08
【问题描述】:
我是 Java 新手,我的 Loops 正在苦苦挣扎。我想创建一个分析投注结果的基本程序。我的 Fixtures 类构造函数:
public Fixtures(String homeTeamName,double homeTeamOdds,String
awayTeamName, double awayTeamOdds,double drawOdds,String result) {
this.homeTeamName=(homeTeamName);
this.homeTeamOdds=(homeTeamOdds);
this.awayTeamName=(awayTeamName);
this.awayTeamOdds=(awayTeamOdds);
this.drawOdds=(drawOdds);
this.result=(result);
}
我已经创建了一个 Fixture 对象的 ArrayList:
Fixtures fixture2= new Fixtures("ManchesterUnited",1.6,"Spurs",3.1,2.8,"home");
Fixtures fixture3= new Fixtures("Manchester Citeh",1.3,"Burnley",4.1,3.8,"home");
Fixtures fixture4= new Fixtures("Newcastle",2.1,"Bomouth",4.1,2.6,"away");
Fixtures fixture5= new Fixtures("Everton",2.1,"Watford",4.6,2.3,"away");
Fixtures fixture6= new Fixtures("Chelsea",2.1,"Brighton",4.1,3.8,"draw");
ArrayList<Fixtures> games = new ArrayList<Fixtures>();
games.add(fixture2);
games.add(fixture3);
games.add(fixture4);
games.add(fixture5);
games.add(fixture6);
现在我想遍历 ArrayList 并找到结果为“主场”获胜的夹具,并将主场获胜几率相乘。我在下面打印出 2 个 homeTeamOdds。然后我想将它们相乘。我被卡住了。对于完成此循环的任何帮助将不胜感激
double x=0;
for (int i = 0; i < games.size(); i++){
if (games.get(i).getResult().equals("home")){
x=(games.get(i).getHomeTeamOdds());
System.out.println(x);
}
【问题讨论】: