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
Michael is stuck due to an electric shock generated at the fridge. What should you do to save michael?.
NISA [10]

Pull him away from the fridge with a non-conducting material and begin cardiopulmonary resuscitation .

<h3>What is meant by electric shock?</h3>

When a human comes into contact with an electrical energy source, they experience an electric shock. A shock is produced when electrical energy passes through a section of the body. Exposure to electrical energy has the potential to cause fatalities or absolutely no injuries.

The tangible and tangible result of an electrical current entering the body is electrical shock. The shock could be anything from a dangerous discharge from a power line to an uncomfortable but safe jolt of static electricity after walking over a thick carpet on a dry day. trauma; related topics.

The complete question is : Michael is stuck due to an electric shock generated at the fridge. What should you do to save Michael?

A. push the fridge away with a non-conducting material and begin cardiopulmonary resuscitation

B. push the fridge away from him and begin cardiopulmonary resuscitation

C. pull him away from the fridge with a non-conducting material and begin cardiopulmonary resuscitation

D .pull him away from the fridge with your hands and begin cardiopulmonary resuscitation

To learn more about electric shock refer to:

brainly.com/question/28361869

#SPJ1

7 0
1 year ago
Niall is revising a history assignment using a word processor on a Windows computer. He wants to copy a section from an earlier
Zarrin [17]

Answer:Ctrl + V

Explanation:

7 0
2 years ago
Alice and Bob are unknown to each other. Alice wants to send an encrypted message to Bob. So it chooses a KDC which is known to
kakasveta [241]

3. ¿Qué mensaje recupera Bob después del descifrado? Mostrar como caracteres hexadecimales.

Respuesta: la clave con el mensaje :

5 0
2 years ago
A(n) ________ variable is declared inside a module and cannot be accessed by statements that are outside the module.
Advocard [28]
Local






----------------------------------------------------
6 0
3 years ago
What is the type of data in the list [103, 405, 527, 396, 503]?
Mariulka [41]

Answer:

alphanumeric.........

3 0
2 years ago
Read 2 more answers
Other questions:
  • A DTP firm has published and printed flyers for an upcoming fundraising event. In which section of the flyer would you find the
    6·2 answers
  • What is zenmap typically used for? how is it related to nmap? describe a scenario in which you would use this type of applicatio
    14·1 answer
  • John's Plumbing prides itself on excellent customer service, especially during after-hours service calls. They want to connect w
    11·1 answer
  • Marissa, a 21-year-old young woman, is working as an intern at a software company. She has recently graduated from college. She
    6·1 answer
  • A project manager is responsible for (check all that apply)
    13·1 answer
  • _____ of a global information system (GIS) concentrates on medium-range activities that move an organization toward achieving lo
    7·1 answer
  • 9.4 Code Practice: Your task is to determine whether each item in the array above is divisible
    14·1 answer
  • Write a pseudocode algorithm that prompts the user to enter a three-digit number and outputs the hundreds, tens and units.
    6·1 answer
  • Is there a way for me to play a .mp3 file from my computer using Atom?
    10·1 answer
  • 4.8% complete this is a single choice question; skip ahead to question content a b c d confirm difficulty level: moderate an int
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!