1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| import javax.swing.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class Exercice2 {
public static void main(String args[]) throws IOException {
final int NB_PARTIS = 3, NB_BUREAUX = 10;
int tabTotParti[] = new int [NB_PARTIS];
int tabTotBureau[] = new int [NB_BUREAUX];
int noParti,
noBureau ,
nbVotes;
String ligne, Partis="", Bureaux="";
String[] tab = new String [6];
BufferedReader fichier = new BufferedReader(
new FileReader("src/votes.txt"));
JTextArea sortie = new JTextArea();
ligne =fichier.readLine();
while(ligne != null)
{
tab = ligne.split(" ");//tab[0]contient le numero bureau, tab[1] contient le numero parti, ...
// tab[2] contient le nombre de votes pour cette partie dans ce bureau
noBureau =Integer.parseInt(tab[0]);
noParti =Integer.parseInt(tab[1]);
nbVotes =Integer.parseInt(tab[2]);
tabTotBureau[noBureau-1]+=nbVotes;
tabTotParti[noParti-1]+=nbVotes;
ligne=fichier.readLine();
}
fichier.close();
sortie.append("PARTI\tTOTAL DES VOTES\n");
sortie.append("\nBUREAU\tTOTAL DES VOTANTS\n");
JOptionPane.showMessageDialog(null, sortie,
"RÉSULTATS DE L'ÉLECTION", JOptionPane.PLAIN_MESSAGE);
} // fin de la cla
} |
Partager