Problem: Cadwell County Board of election need your help in determining the winn
ID: 3665288 • Letter: P
Question
Problem: Cadwell County Board of election need your help in determining the winnner of the election for School Superintendent. You have been asked to develop a Java program by the board of Elections.
The results of the election:
Your program should do the following
Determine the winner
Display the candidates with their total numberof vote.
Display a congratulatory message to the candidate with the highest number of votes.
Determine the distric that had the highest voter turnout.
display the name of the district and the number of voter for the districwith the highest
Display the name and votes of the candidate with the highest number of votes from each district
Candidates Distric1 Distric2 Distic3 Cadwell 1000 300 400 Gresham 200 100 800 Johnson 400 700 100Explanation / Answer
public class Election {
public static void main(String args[]) {
int[] cadwell = {1000, 300, 400};
int[] gresham = {200, 100, 800};
int[] johnson = {400, 700, 100};
int[] totalVotes = new int[3];
for (int votes: cadwell) {
totalVotes[0] += votes;
}
for (int votes: gresham) {
totalVotes[1] += votes;
}
for (int votes: johnson) {
totalVotes[2] += votes;
}
System.out.println("Cadwell : " + totalVotes[0]);
System.out.println("Gresham : " + totalVotes[1]);
System.out.println("Johnson : " + totalVotes[2]);
if (totalVotes[0] > totalVotes[1] && totalVotes[0] > totalVotes[2])
System.out.println("Winner is Cadwell. Congratulations!!!");
if (totalVotes[1] > totalVotes[0] && totalVotes[1] > totalVotes[2])
System.out.println("Winner is Gresham. Congratulations!!!");
if (totalVotes[2] > totalVotes[0] && totalVotes[2] > totalVotes[1])
System.out.println("Winner is Johnson. Congratulations!!!");
int districtTotalVotes[] = new int[3];
for (int i = 0; i < 3; i++) {
districtTotalVotes[i] = cadwell[i] + gresham[i] + johnson[i];
}
if (districtTotalVotes[0] > districtTotalVotes[1] && districtTotalVotes[0] > districtTotalVotes[2])
System.out.println("District 1 has highest vote turn out! Number of voters = " + districtTotalVotes[0]);
if (districtTotalVotes[1] > districtTotalVotes[0] && districtTotalVotes[1] > districtTotalVotes[2])
System.out.println("District 2 has highest vote turn out! Number of voters = " + districtTotalVotes[1]);
if (districtTotalVotes[2] > districtTotalVotes[0] && districtTotalVotes[2] > districtTotalVotes[1])
System.out.println("District 3 has highest vote turn out! Number of voters = " + districtTotalVotes[2]);
System.out.println("From District 1:");
if (cadwell[0] > gresham[0] && cadwell[0] > johnson[0])
System.out.println("Cadwell with " + cadwell[0] + " votes");
if (gresham[0] > cadwell[0] && gresham[0] > johnson[0])
System.out.println("Gresham with " + gresham[0] + " votes");
if (johnson[0] > gresham[0] && cadwell[0] < johnson[0])
System.out.println("Johnson with " + johnson[0] + " votes");
System.out.println("From District 2:");
if (cadwell[1] > gresham[1] && cadwell[1] > johnson[1])
System.out.println("Cadwell with " + cadwell[1] + " votes");
if (gresham[1] > cadwell[1] && gresham[1] > johnson[1])
System.out.println("Gresham with " + gresham[1] + " votes");
if (johnson[1] > gresham[1] && cadwell[1] < johnson[1])
System.out.println("Johnson with " + johnson[1] + " votes");
System.out.println("From District 3:");
if (cadwell[2] > gresham[2] && cadwell[2] > johnson[2])
System.out.println("Cadwell with " + cadwell[2] + " votes");
if (gresham[2] > cadwell[2] && gresham[2] > johnson[2])
System.out.println("Gresham with " + gresham[2] + " votes");
if (johnson[2] > gresham[2] && cadwell[2] < johnson[2])
System.out.println("Johnson with " + johnson[2] + " votes");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.