-
-
Save lrlucena/27bad7754813f12429dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.Collections; | |
import java.util.Comparator; | |
import java.util.List; | |
import java.util.Scanner; | |
public class Ranking { | |
static class Participante { | |
public final String nome; | |
public final int nota; | |
public Participante(String nome, int nota) { | |
this.nome = nome; | |
this.nota = nota; | |
} | |
public String dados() { | |
return nome + " - " + nota; | |
} | |
} | |
public static void main(String... args) { | |
final Scanner sc = new Scanner(System.in); | |
final List<Participante> pessoas = new ArrayList(200); | |
for (int i = 0; i <= 200; i++) { | |
System.out.println("Digite o nome: "); | |
final String nome = sc.nextLine(); | |
System.out.println("Digite a nota: "); | |
final int nota = sc.nextInt(); | |
pessoas.add(new Participante(nome, nota)); | |
} | |
Collections.sort(pessoas, new Comparator<Participante>() { | |
@Override | |
public int compare(Participante o1, Participante o2) { | |
return o1.nota - o2.nota; | |
} | |
}); | |
for (Participante p : pessoas) { | |
if (p.nota > 70) { | |
System.out.println(p.dados()); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class Participante(nome: String, nota: Int) { | |
override def toString = nome + " - " + nota | |
} | |
object Rank extends App { | |
val pessoas = | |
for (i <- 1 to 200) yield { | |
print(s"Digite o nome do ${i}º Candidato: ") | |
val nome = readLine | |
print("Digite a nota: ") | |
val nota = readInt | |
Participante(nome, nota) | |
} | |
pessoas.filter(_.nota > 70) | |
.sortBy(_.nota) | |
.reverse | |
.foreach(println) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment