Skip to content

Instantly share code, notes, and snippets.

@diogocapela
Last active June 28, 2018 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diogocapela/85918234d905471ef28c0f940bfa3f8e to your computer and use it in GitHub Desktop.
Save diogocapela/85918234d905471ef28c0f940bfa3f8e to your computer and use it in GitHub Desktop.
import java.util.ArrayList;
import java.util.List;
public class Escrutinio {
// variaveis de insância
private List<Candidato> candidatos;
private int numEleitores;
private int numVot;
private int data;
// construtor
public Escrutinio(List<Candidato> candidatos, int numEleitores, int data) {
this.candidatos = candidatos;
this.numEleitores = numEleitores;
this.numVot = 0;
this.data = data;
}
// metodos
public void calcularVotantes() {
for(Candidato candidato : candidatos) {
numVot = numVot + candidato.getNumVotos();
}
}
public void inicializarVotosCandidatos() {
for(Candidato candidato : candidatos) {
candidato.inicializarNumVotos();
}
}
public List<Candidato> vencedor() {
List<Candidato> vencedores = new ArrayList<>();
int maxVotos = 0; // 50
for(Candidato candidato : candidatos) {
int numVotosCandidato = candidato.getNumVotos();
if(numVotosCandidato >= maxVotos) {
maxVotos = numVotosCandidato;
}
}
for(Candidato candidato : candidatos) {
int numVotosCandidato = candidato.getNumVotos();
if(numVotosCandidato == maxVotos) {
vencedores.add(candidato);
}
}
return vencedores;
}
}
public class Voto {
private Candidato candidato;
private int data;
private int dataLim;
public Voto(Candidato candidato, int data, int dataLim) {
this.candidato = candidato;
this.data = data;
this.dataLim = dataLim;
}
public boolean eValido() {
return this.data <= this.dataLim;
}
@Override
public String toString() {
if(this.eValido()) {
return this.candidato.getNome() + " -> válido"
}
return this.candidato.getNome() + " -> inválido"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment