Last active
June 28, 2018 17:29
-
-
Save diogocapela/85918234d905471ef28c0f940bfa3f8e to your computer and use it in GitHub Desktop.
This file contains hidden or 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.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; | |
} | |
} | |
This file contains hidden or 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
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