1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Arisa [49]
3 years ago
8

Instructions Write a program that allows the user to enter the last names of five candidates in a local election and the number

of votes received by each candidate. The program should then output each candidate’s name, the number of votes received, 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.73 Duffy 6000 31.09 Robinson 2500 12.95 Ashtony 1800 9.33 Total 19300 The Winner of the Election is Duffy
Computers and Technology
1 answer:
KengaRu [80]3 years ago
8 0

Here is code in java.

import java.util.*;

class Election

{ //main method

   public static void main(String args[]){

      // create an object of Scanner class to read input

      Scanner s = new Scanner(System.in);

      // string array to store name of candidates

       String name[] = new String[5];

       // int array to store vote count of candidates

       int v_count[] = new int[5];

       double p = 0;

       int i = 0, sum = 0, high =0, win = 0;

for(i = 0; i < 5;i++)

       {

          System.out.print("last name of Candidate " + (i+1) + ":");

          // read name of Candidate

          name[i] = s.next();

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

          // read vote of Candidate

           v_count[i] =s.nextInt();

if(v_count[i] > high)

              {

                  // highest vote

                  high = v_count[i];

                  win = i;

              }

              // total vote count

           sum +=v_count[i];

       }

     // printing the output

      System.out.println("\nCandidate\tVotes Received\t% of TotalVotes\n");

       for(i = 0; i < 5;i++)

       {

           // % of vote of each Candidate

           p =(v_count[i]*100)/sum;

           // print the output

          System.out.println(name[i] + "\t\t" + v_count[i] + "\t\t\t" +p);

       }

       // print the total votes

      System.out.println("\nTotal Votes:\t" + sum);

      // print the Winner of the Election

       System.out.println("Winner of the Election is: " + name[win]);

   }

}

Explanation:

Create a string array "name" to store the name of candidates.Create Integer array "v_count" to store votes os each candidates.Calculate total votes of all candidates and find the highest vote amongst all candidate and print it.Find % of votes received by each candidate.Print these stats.

Output:

last name of Candidate 1:patel

number of votes received: 54

last name of Candidate 2:singh

number of votes received: 76

last name of Candidate 3:roy

number of votes received: 33

last name of Candidate 4:yadav

number of votes received: 98

last name of Candidate 5:sharma

number of votes received: 50

Candidate       Votes Received  % of TotalVotes

patel           54                      17.0

singh           76                      24.0

roy             33                      10.0

yadav           98                      31.0

sharma          50                      16.0

Total Votes:  311

Winner of the Election is: yadav

You might be interested in
Why are rules required for a number system to be useful?
evablogger [386]

Answer

This is because without them no one would know how much each symbol represents, and no one would be able to decipher the message.

Explanation

Number system is a way to represent numbers. It  is a writing system for expressing numbers; that is, a mathematical notation for representing numbers of a given set, using digits or other symbols in a consistent manner.

In computing or in a computer number systems are the techniques which represents numbers in the computer system architecture where   every value that you are saving or getting into/from computer memory has a defined number system.Computer architecture supports  . Binary number system,Octal number system and Decimal number system.

5 0
3 years ago
Read 2 more answers
Alison is having a hard time at work because her Inbox is flooded with emails every day. Some of these emails are unsolicited. S
EastWind [94]

Answer:

create another email for a buisness and private/personal. important emails will go to her personal while junk and un needed emails will go to the buisness

Explanation:

8 0
3 years ago
Read 2 more answers
6. By default,how the table headings are placed. (2 Points)
Dmitrij [34]
They are all bold and what ever else
6 0
3 years ago
What is the maximum duration of daily scrum meetings A:15minsB:45minsC10mins:30mins
scoray [572]

Answer:

A

Explanation:

A common approach to a daily scrum (although not the only approach) is for each member of the development team to address the following three daily scrum questions:

1. What did I accomplish since the last daily scrum?

2. What do I plan to work on by the next daily scrum?

3. What are the obstacles or impediments that are preventing me from making progress?

Development teams are typically between five to nine people. Each development team member should need no more than 90 seconds to address the three questions listed above. So, if you had a team of nine people, each of whom took 90 seconds to cover the questions, combined with some overhead of getting the meeting started and transitioning from person to person, you would end up with a meeting duration of about 15 minutes.

To emphasize that 15 minutes should be thought of as a timeboxed limit.

8 0
3 years ago
Read 2 more answers
How do I get rid of the thing on top? It is driving me INSANE!!
Zinaida [17]
Try restarting your laptop?
7 0
3 years ago
Other questions:
  • REEEEEEE I STILL NEED MORE AESTHETIC USERNAMES TO GO OFF OF PWEASE HELP IMA HAVE A PANIC ATTACK!!!... next post ima do a vote :&
    13·1 answer
  • Write qbasic code for given pattern<br><br>NEPAL<br>. EPA<br>. P​
    12·1 answer
  • sara has just started using the Internet. She would like to be more efficient . In 3-4, give sara some advice about how to be mo
    5·1 answer
  • Write a program using integers userNum and x as input, and output userNum divided by x three times.
    11·1 answer
  • The term integration refers to the ability to
    9·1 answer
  • By
    7·1 answer
  • Authentication is a mechanism whereby unverified entities or supplicants who seek access to a resource provide a label by which
    12·1 answer
  • Match the image to the view type in a presentation program. scroll bar tool bar status bar menu bar provides an array of buttons
    10·2 answers
  • One of the benefits of holding an investment for over a year rather than selling it in less than a year is that the
    14·2 answers
  • What are the advantages of mine shaft gear and the disadvantaged​
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!