what i did was if a team performance entry for the home team already exists, it should be updated if a team performance entry for the home team already does not exist, it should be added * same goes for the away team
and this is what i've tried
public void addMatchEntry(Match m)
{
boolean homeExist = false;
boolean awayExist = false;
for(int i = 0; i < tableEntries.size(); i++) {
if(tableEntries.get(i).getName().equals(m.getHomeTeam()))
homeExist = true;
tableEntries.get(i).addMatchRecord(m);
break;
}
if(homeExist == false)
tableEntries.add(new TeamPerformance(m.getHomeTeam(), m.getHomeGoals(), m.getAwayGoals()));
for(int i = 0; i < tableEntries.size(); i++) {
if(tableEntries.get(i).getName().equals(m.getAwayTeam()))
awayExist = true;
tableEntries.get(i).addMatchRecord(m);
break;
}
if(awayExist == false)
tableEntries.add(new TeamPerformance(m.getAwayTeam(), m.getAwayGoals(), m.getHomeGoals()));
Collections.sort(tableEntries, Collections.reverseOrder());
}
Aucun commentaire:
Enregistrer un commentaire