Question: Java programming I keep having some issues with my program and I'm trying to get it how my teacher wants it. I've already modified the

Java programming I keep having some issues with my program and I'm trying to get it how my teacher wants it. I've already modified the program from the answers I have gotten from chegg already can you help with this program?

These are the instructions:

java programming 5th edition chapter 9 Parallel Arrays

Write a program that allows the user to enter the last names of five candidites in a local election and the votes received by each candidate. The program should then output each candidate's name, the votes receive by that candidate, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. Make sure your output is in table format. A sample output is:

Candidate Votes Received % of Total Votes

_____________________________________________

Johnson 5000 25.91

Miller 4000 20.73

Duffy 6000 31.09

Robinson 2500 12.95

Ashtony 1800 9.33

__________________________________________________

Total 19300

The Winner of the Election is Duffy

This is the Program

import java.util.*;

public class CandidateVotes

{

static Scanner keyboard = new Scanner(System.in);

public static void main(String[] args)

{

//Declare variables

String winnerName = ;

int winnerVotes = 0;

int total = 0;

double percentage;

//Declare Parallel Arrays

int[] votes = new int[5];

String[] names = new String[5];

for(int i = 0; i < winnerNames.length(); i = i + 1)

{

System.out.print( Enter name of the Cadidate: );

names[i] = keyboard.nextLine();

System.out.println();

System.out.print( Enter number of votes received: );

Votes[i] = keyboard.nextInt();

}//end for

System.out.println( Candidate Votes Received % of Total Votes);

System.out.println(______________________________________________);

//Calculate Total Votes

for(int i = 0; i < votes.length; i++)

{

total+= votes[i];

}//end for

//Loop to find winner

for(int i = 0; i < names.length; i++)

{

//If number of votes greater than winner votes

if(votes[i] > winnerVotes)

{

winnerVotes = votes[i]; //Change votes

winnerName = names[i]; // Change name

}//end if

//Calculate the percentage of votes

percentage = (double)(votes[i] / total) * 100;

System.out.println(names[i] + +(int)votes[i] + + percentage);

}//end for

System.out.println(_____________________________________________);

System.out.println(Total + total);

System.out.println();

System.out.println(The winner of the election is + winnerName);

}//end main

}//end class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!