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.
This is the code that I have so far. I got it to compile and print into the correct format. I am having trouble getting the program to allow the user to input the candidates and the votes received. Can someone please help
import java.util.*;
import java.text.NumberFormat;
public class Election
{
public static void main(String[] args)
{
String[] names = new String [5];
int[] votes = new int[5];
String winner = "";
int winnerVotes = 0;
int totalVotes = 0;
int j;
for (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 (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);
}//main
}//election