eu fiz a alteração… consegui resolver este problema mas estou fazendo uma puta gambiarra… estou fazendo tudo no método que chamo sem a necessidade de lhe passar argumentos alguns e o mesmo está me retornando uma string com as dezenas mais sorteadas, estou jogando esta string dentro de um jtextarea, mesmo assim vou colocar o pacote inteiro aqui pois preciso saber o porque daquele erro…
package br.unipaulistana.prog3.quina;
// clase que usarei para fazer a ordenação das dezenas mais sorteadas
public class Dezena implements Comparable <Dezena> {
private int valor;
private int numSorteados;
public int getValor() {
return valor;
}
public void setValor(int valor) {
this.valor = valor;
}
public int getNumSorteados() {
return numSorteados;
}
public void setNumSorteados(int numSorteados) {
this.numSorteados = numSorteados;
}
@Override
public int compareTo(Dezena dezena) {
if (numSorteados < dezena.numSorteados) {
return -1;
} else if (numSorteados == dezena.numSorteados) {
return 0;
} else
return 1;
}
}
package br.unipaulistana.prog3.quina;
// classe que terá todas as funçoes que pretendo fazer.....
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.StringTokenizer;
import javax.swing.JOptionPane;
public class Funcoes {
public String lerArquivo(File file) throws IOException {
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(file));
StringBuilder sb = new StringBuilder();
String linha = "Sorteiro\t1ª Dezena\t2ª Dezena\t3ª Dezena\t4ª Dezena\t5ªDezena\n";
sb.append(linha + "\n");
while ((linha = br.readLine()) != null) {
sb.append(linha + "\n");
}
br.close();
return sb.toString();
} finally {
if (br != null) {
br.close();
}
}
}
public String exibirHistorico(File file) {
String historico = "";
try {
historico = lerArquivo(file);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Erro ao exibir histórico",
"Erro de Leitura", JOptionPane.ERROR_MESSAGE);
}
return historico;
}
public Dezena[] maisSorteadas(Dezena[] dezenas, File file) throws IOException {
int[] sorteados = new int[dezenas.length];
BufferedReader leitor = null;
try {
leitor = new BufferedReader(new FileReader (file));
StringTokenizer st = null;
int valor;
String linha;
String temp;
while ((linha = leitor.readLine()) != null) {
st = new StringTokenizer(linha);
while (st.hasMoreTokens()) {
temp = st.nextToken();
valor = Integer.parseInt(temp);
++sorteados[valor + 1];
}
}
leitor.close();
} finally {
if (leitor != null) {
leitor.close();
}
}
for (int i = 0; i < dezenas.length; i++) {
dezenas[i] = new Dezena();
dezenas[i].setValor(i + 1);
}
for (int j = 0; j < sorteados.length; j++) {
dezenas[j].setNumSorteados(sorteados[j]);
}
Arrays.sort(dezenas);
return dezenas;
}
public void adicionarResultado() {
int valorSorteado;
int qtdSorteado = 0;
int numSorteio;
do {
if (qtdSorteado == 0) {
try {
String a = JOptionPane.showInputDialog("Digite o número do sorteio");
numSorteio = Integer.parseInt(a);
qtdSorteado++;
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Você executou uma operação ilegal",
"Operação Ilegal", JOptionPane.INFORMATION_MESSAGE);
continue;
}
} else {
try {
String b = JOptionPane.showInputDialog("Digite a "
+ qtdSorteado + "ª dezena sorteada");
valorSorteado = Integer.parseInt(b);
if (valorSorteado > 0 && valorSorteado <= 80) {
qtdSorteado++;
} else {
JOptionPane.showMessageDialog(null,
"Você deve digitar um valor entre 1 e 80",
"Dezena Inválida",
JOptionPane.INFORMATION_MESSAGE);
}
} catch (Exception i) {
JOptionPane.showMessageDialog(null,
"Você executou uma operação ilegal",
"Operação Ilegal", JOptionPane.INFORMATION_MESSAGE);
}
}
} while (qtdSorteado <= 5);
}
}
package br.unipaulistana.prog3.quina;
// classe principal com todas as telas do programa
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;
public class QuinaMuitaSorte2007 extends JFrame implements ActionListener {
private JLabel textoTela; // Texto da tela principal
private JTextArea telaSorteados; // Exibir aqui os resultados
private JButton botaoAdd; // Botão para add novo resultado
private JButton botaoExibirHist; // Botão para exibir o histórico dos sorteios
private JButton botaoDezSort; // Botão par exibir as dezenas mais sorteadas
Funcoes funcoes = new Funcoes(); // classe com as funções do programa
File conteudoDezenas = new File("C:\\ResultadosQuina.txt"); // arquivo com os resultados
Dezena[] dezenas = new Dezena[79];
public QuinaMuitaSorte2007(String titulo) {
super(titulo);
textoTela = new JLabel("O QUE VOCÊ DESEJA FAZER?");
textoTela.setHorizontalAlignment(SwingConstants.CENTER);
botaoAdd = new JButton("ADICIONAR");
botaoAdd.setToolTipText("Clique aqui para adicionar um novo resultado");
botaoAdd.addActionListener(this);
botaoExibirHist = new JButton("EXIBIR HISTÓRICO");
botaoExibirHist.setToolTipText("Clique aqui para exibir o histórico dos sorteios");
botaoExibirHist.addActionListener(this);
botaoDezSort = new JButton("DEZENAS MAIS SORTEADAS");
botaoDezSort.setToolTipText("Clique aqui para exibir as dezenas mais sorteadas em "
+ "ordem crescente");
botaoDezSort.addActionListener(this);
telaSorteados = new JTextArea(10, 5);
telaSorteados.setEditable(false);
}
private void mostrarTela() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridLayout(3, 1));
setLocation(200, 100);
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(1, 1));
// 1ª Linha
panel.add(textoTela);
// 2ª Linha
JPanel panel2 = new JPanel();
panel2.setLayout(new GridLayout(1, 3));
panel2.add(botaoAdd);
panel2.add(botaoExibirHist);
panel2.add(botaoDezSort);
// 3ª Linha
JScrollPane scroll = new JScrollPane(telaSorteados);
getContentPane().add(panel);
getContentPane().add(panel2);
getContentPane().add(scroll, BorderLayout.CENTER);
pack();
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == botaoAdd) {
telaSorteados.setText("");
funcoes.adicionarResultado();
}
if (e.getSource() == botaoExibirHist) {
String historico = "";
try {
historico = funcoes.exibirHistorico(conteudoDezenas);
telaSorteados.setText(historico);
telaSorteados.setCaretPosition(0);
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "Erro ao exibir histórico",
"Erro de Leitura", JOptionPane.ERROR_MESSAGE);
}
}
if (e.getSource() == botaoDezSort) {
dezenas = funcoes.maisSorteadas(dezenas, conteudoDezenas);
}
}
public static void main(String[] args) {
QuinaMuitaSorte2007 executar = new QuinaMuitaSorte2007("Quina Muita Sorte 2007");
executar.mostrarTela();
}
}
segue um exemplo do meu arquivo txt… nao vo colocar ele inteiro posi tem mais de 1800 linhas…
sorteio …dezenas…
1 25 45 60 76 79
2 13 30 58 63 64
3 5 15 32 33 48
4 27 57 60 61 77
5 19 44 53 54 71
6 4 45 54 65 67
7 9 21 37 42 68
8 5 16 26 28 62
9 4 15 44 64 73
10 20 32 49 54 62
11 17 33 52 60 76
12 1 28 56 65 79
13 13 33 38 39 72
14 44 52 60 64 68
15 2 25 54 63 66
16 11 24 63 64 69
17 1 14 26 34 72
18 6 29 40 63 72
19 12 21 42 60 66
20 13 16 31 39 70
21 5 15 38 48 77
22 7 9 11 25 75
23 1 15 63 72 77
24 9 44 57 67 68
25 2 29 46 69 76
26 10 15 22 55 79
27 5 36 39 70 78
28 8 26 28 29 30
29 20 23 31 35 76
30 12 13 14 56 60
31 43 51 54 69 73
32 9 23 31 60 80
33 21 31 44 65 74
34 17 45 64 67 69
35 44 52 54 56 60
36 42 56 62 65 79
37 9 26 31 36 65
38 11 12 57 59 69
39 5 7 21 28 70
40 2 18 31 38 49
41 5 14 31 41 49
42 15 33 39 76 78
43 5 18 21 41 71
44 2 7 57 59 76
45 2 3 27 64 65
46 30 49 72 78 80
47 10 18 22 31 73
48 20 39 72 73 76
49 10 19 39 52 66
50 4 10 15 42 45
valeu galera…