Meu professor me passou uma urna eletrônica mas eu não estou conseguindo finalizar esta urna alguem pode me ajudar?
ele quer que totalize o total de votos de cada deputado, quantos votos em branco e, quantos nulos e o vencedor e os votos .
são três classe
eis as classes
package urna;
public class Urna {
private String nome;
private int numero;
public Urna (String nome, int numero){
this.nome= nome;
this.numero= numero;
}
public int getNumero() {
return numero;
}
public void setNumero(int numero) {
this.numero = numero;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String toString(){
return "\nNome: "+nome + "\nNumero: "+getNumero();
}
}
2°
package urna;
import java.util.*;
import javax.swing.JOptionPane;
import aula7.Empregado;
public class ClassificaDputados {
List<Urna> deputados;
List<Urna> numeros;
public ClassificaDputados() {
deputados = new ArrayList<Urna>();
numeros = new ArrayList<Urna>();
}
public void addDeputado(Urna urna) {
deputados.add(urna);
}
public void classifica() {
for (Urna urna : deputados) {
int cont=0;
int cont2=0;
int cont3=0;
if (urna.getNumero() == 25 && urna.getNome().equals("ze do ovo")) {
deputados.add(urna);
cont= cont+1;
} else if (urna.getNumero() == 13 && urna.getNome().equals("joão")){
deputados.add(urna);
cont2=cont2+1;
} else if (urna.getNumero() == 23 && urna.getNome().equals("jose")){
deputados.add(urna);
cont3=cont3+1;
}
}
}
public void listaDeputados() {
JOptionPane.showMessageDialog(null, "Candidatos:" + deputados);
}
}
3°
package urna;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Tela extends JFrame {
private JTextField tfDeputado, tfNumero;
private JButton btVotar, btResultado, btBranco, btNulo;
ClassificaDputados classificaDputados = new ClassificaDputados();
public Tela() {
setTitle("Urna Eletrônica");
setLayout(new FlowLayout());
// labels
JLabel lbNumero = new JLabel("Numero:");
JLabel lbNome = new JLabel("Nome: ");
JLabel lbNome1 = new JLabel(" Numero: 25 \n Nome: Zé do ovo");
JLabel lbNome2 = new JLabel("Numero: 13 - Nome: Sariema");
JLabel lbNome3 = new JLabel("Numero: 30 - Nome: Cordoba");
// caixa de texto
tfDeputado = new JTextField(15);
tfNumero = new JTextField(15);
// botões
btVotar = new JButton("Votar");
btResultado = new JButton("Resultado");
btBranco = new JButton("Voto em branco");
btNulo = new JButton("Voto Nulo");
add(lbNumero);
add(tfNumero);
add(lbNome);
add(tfDeputado);
add(lbNome1);
add(lbNome2);
add(lbNome3);
add(btVotar);
add(btResultado);
add(btBranco);
add(btNulo);
EventoAdd eventoAdd = new EventoAdd();
btVotar.addActionListener(eventoAdd);
EventoVencer eventoVencer = new EventoVencer();
btResultado.addActionListener(eventoVencer);
EventoNuloBranco eventoNuloBranco = new EventoNuloBranco();
btBranco.addActionListener(eventoNuloBranco);
btNulo.addActionListener(eventoNuloBranco);
setSize(200, 300);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(true);
}
private class EventoAdd implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
String nome = tfDeputado.getText();
int numero = Integer.parseInt(tfNumero.getText());
Urna urna = new Urna(nome, numero);
classificaDputados.addDeputado(urna);
tfDeputado.setText("");
tfNumero.setText("");
}
}
private class EventoVencer implements ActionListener {
@Override
public void actionPerformed(ActionEvent arg0) {
classificaDputados.classifica();
classificaDputados.listaDeputados();
}
}
private class EventoNuloBranco implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btBranco) {
int cont = 0;
cont = cont + 1;
} else if (e.getSource() == btNulo) {
int cont2 = 0;
cont2 = cont2 + 1;
}
}
}
public static void main(String[] args) {
new Tela();
}
}
ME AJUDEM POR FAVOR