private static ArrayList<Game> Winners(ArrayList<Game> gamers) {
ArrayList<Game> winner = new ArrayList<Game>();
for (int i = 1; i < gamers.size(); i++) {
winner.clear();
if (gamers.get(i).getPoints() > gamers.get(i - 1).getPoints()) {
winner.add(gamers.get(i));
} else if (gamers.get(i).getPoints() < gamers.get(i - 1).getPoints()) {
winner.add(gamers.get(i - 1));
} else { // last check when points are equal
winner.add(gamers.get(i));
winner.add(gamers.get(i - 1));
}
}
return winner;
}
lets say that gamers contain 5 elements. a, b, c, d, e
i then want to loop through each on of them and store the one that has the highest points of them in the winner arraylist. then i want to return it.
for example if,
a.points=1 and b.Points=2 and c.points=3 and d.points=10 and e.points=21,
then i want to store element e in winner arraylist.
if a.points=1 and b.points=20 and c.points=20 and d.points=20 and e.points=10 i want to store element b,c, and d in winner arraylist, because they share the highest points.
if a.points=1 and b.points=1 and c.points=1 and d.points=1 and e.points=1 i want to store element a,b,c,d and e in winner arraylist, because they all share the highest points.
so basically i want the element or elements that share the highest score, in the winner arraylist.
i have troubles solving this issue. how do i fix it in the if statement.
Aucun commentaire:
Enregistrer un commentaire