vendredi 16 septembre 2016

Java loop if statement highest point

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 contain 5 . a, b, c, d, e

i then want to loop through each on of them and store the one that has the highest of them in the . then i want to 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 e in .

if a.points=1 and b.points=20 and c.points=20 and d.points=20 and e.points=10 i want to store b,c, and d in , because they share the highest .

if a.points=1 and b.points=1 and c.points=1 and d.points=1 and e.points=1 i want to store a,b,c,d and e in , because they all share the highest .

so basically i want the or that share the highest score, in the .

i have troubles solving this issue. how do i fix it in the if statement.

Aucun commentaire:

Enregistrer un commentaire