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
| import javax.swing.*;
import java.io.*;
public class Exercice2 {
private static JTextArea sortie;
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 = 0,
noBureau = 0,
nbVotes;
String[] tab = new String [3];
String ligne;
BufferedReader fichier = new BufferedReader(
new FileReader("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 = null;
sortie.append("PARTI\tTOTAL DES VOTES\n");
sortie.append("\nBUREAU\tTOTAL DES VOTANTS\n");
for ( int i = 1 ; i < noParti; i++ );
sortie.append(tabTotBureau[noBureau-1] + "\t" + tabTotParti[noParti-1] + "\n");
JOptionPane.showMessageDialog(null, sortie,
"RÉSULTATS DE L'ÉLECTION", JOptionPane.PLAIN_MESSAGE);
System.exit(0);
} // fin de la cla
} |
Partager