Bom galera, estou tentado fazer um código em java que gere um tabela de jogos e os confrontos. Consegui fazer uma parte do código, mas não tô conseguindo por na tabela a quantidade de pontos de cada time o o saldo de gols dos mesmos de cada confronto. A quantidade de pontos e o saldo de gol é para ir no comando tabela.add(clube[], pontos, saldo)
, não consigo por os pontos e o saldo ali. Se puderem me ajudar, segue código:
public class main {
public static void main(String[] args) {
String clube[] = new String[3];
clube[0] = "Alemanha";
clube[1] = "Brasil";
clube[2] = "Argentina";
Random ran = new Random();
List<Time> tabela = new ArrayList<>();
System.out.println("╔════════════════╗");
System.out.println("║ PRIMEIRA RODADA║");
System.out.println("╚════════════════╝");
for (int i = 0; i < 3; i++) {
int x = ran.nextInt(5);
for (int j = 0; j < 3; j++) {
int y = ran.nextInt(5);
if (i != j) {
System.out.printf("");
System.out.print(clube[i] + " ");
System.out.print(x + " x " + y);
System.out.println(" " + clube[j]);
}
}
}
System.out.println("════════════════════");
tabela.add(new Time(clube[0], /*pontos*/, /*saldo de gol*/));
tabela.add(new Time(clube[1], /*pontos*/, /*saldo de gol*/));
tabela.add(new Time(clube[2], /*pontos*/, /*saldo de gol*/));
//Ordeno os dados
Collections.sort(tabela, (Object o1, Object o2) -> {
Time time1 = (Time) o1;
Time time2 = (Time) o2;
int retorno;
//Verifica se os pontos sao iguais
if (Objects.equals(time1.getPontos(), time2.getPontos())) {
//Se forem verifica quem tem mais gols
if (time1.getGols() > time2.getGols()) {
retorno = -1;
} else {
if (time1.getGols() < time2.getGols()) {
retorno = 1;
} else {
retorno = 0;
}
}
//Senao verifica quem tem mais pontos
} else if (time1.getPontos() > time2.getPontos()) {
retorno = -1;
} else {
if (time1.getPontos() < time2.getPontos()) {
retorno = 1;
} else {
retorno = 0;
}
}
return retorno;
});
//Mostra as posicoes na tabela
int posicao = 1;
for (Time time : tabela) {
System.out.println("Posicao: " + posicao + " | Nome: " + time.getNome() + " | Pontuacao: " + time.getPontos() + " | Saldo de gol: " + time.getGols());
posicao++;
}
}}
Classe do time:
class Time {
String nome;
int gols;
int pontos;
public int getPontos() {
return pontos;
}
public void setPontos(int pontos) {
this.pontos = pontos;
}
public Time(String time, int pontos, int gols) {
this.nome = time;
this.gols = gols;
this.pontos = pontos;
}
public String getNome() {
return nome;
}
public void setNome(String time) {
this.nome = time;
}
public int getGols() {
return gols;
}
public void setGols(int gols) {
this.gols = gols;
}
}