We will have the text file “polls.txt” containing the information/details of the number of Votes which each party have through out the country form different parts.
Our “polls.txt” will look like as shown below.
Voteing detail.
RegionPartyAPartyB
NA120002100
NA220001950
NA330001950
NA410001950
NA520001950
NA620001950
NA778002050
NA820008950
NA920001950
NA1020001950
NA1140001950
NA1211003000
NA1335007000
program will read this file, and will read the number of votes for each party for each regain.
After that program will calculate the total number of votes for party and will print the following information on the console.
Total Number of votes obtained by Party A: 23800
Total Number of votes obtained by Party B: 26750
Party B has won by 2950 Votes
I made this but there is some confusion in totaling the number of votes please read the below code and solve this problem.
2006-10-24
14:29:43
·
1 answers
·
asked by
Anonymous
in
Computers & Internet
➔ Programming & Design
import java.io.*;
public class Selecter
{
public static void main (String args[ ])
{
FileReader fr = null;
BufferedReader br = null;
try {
fr = new FileReader("polls.txt");
br = new BufferedReader(fr);
String line = br.readLine();
br.close();
fr.close();
}
catch(IOException ioex)
{
System.out.println(ioex);
}
}
}
2006-10-24
14:31:16 ·
update #1