I am working on the following Java application
Write a program that allows the user to enter the last names of five candidates in a local election and the votes received by each candidate. The program should then output each candidate’s name, the votes received by that candidate, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. A sample output is:
Candidate Votes Received % of Total Votes
Johnson 5000 25.91
Miller 4000 20.72
Duffy 6000 31.09
Robinson 2500 12.95
Anthony 1800 9.33
Total 19300
The Winner of the Election is Duffy.
import java.util.*;
import java.text.NumberFormat;
public class Election
{
public static void main(String[] args)
{
String[] names = {args[0],args[2],args[4],args[6],args[8]};
int[] votes = {(integer.getInteger(args[1]).intValue()),(integer.getInteger(args[3]).intValue()),
(integer.getInteger(args[5]).intValue()), (integer.getInteger(args[7]).intValue()),
(integer.getInteger(args[9]).intValue())};
String winner = "";
int winnerVotes = 0;
int totalVotes = 0;
for(int j = 0; j < votes.length; j++);
{
totalVotes += votes[j];
}
NumberFormat formatter = NumberFormat.getNumberInstance();
formatter.setMinimumIntegerDigits(1);
formatter.setMaximumFractionDigits(2);
System.out.println("\nCandidate Votes Received % of Total Votes");
System.out.println("--------- --------------- ---------------");
for(int j = 0; j<names.length; j++)
{
if (votes[j] > winnerVotes)
{
winner = names[j];
winnerVotes = votes[j];
}
System.out.println(
names[j] + "\t\t"
+ (int)votes[j] + "\t\t"
+ (formatter.format(
( (double)votes[j] / totalVotes )*100)));
}
System.out.println("Total " + totalVotes);
System.out.println("The winner of the election is " + winner);
}
}