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]
2 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]2 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
How many bytes make up a megabyte? One hundred One thousand One million One billion
Phoenix [80]
One million is the answer.
4 0
3 years ago
Imagine that you work for a company directly related to your major. Your company is preparing for expansion and your boss, Ms. S
shutvik [7]

Answer:

start with what you know

Explanation:

6 0
2 years ago
What is your understanding about the subject “digital image processing”?
N76 [4]

Answer:

Here's your answer mate.....☺️☺️

Explanation:

In computer science, digital image processing is the use of a digital computer to process digital images through an algorithm. ... It allows a much wider range of algorithms to be applied to the input data and can avoid problems such as the build-up of noise and distortion during processing.

<em><u>Hope it helps </u></em>☺️

5 0
3 years ago
Write a full class definition for a class named Counter, and containing the following members: A data member counter of type int
vfiekz [6]

// making the class

class Counter {

int counter;

int limit;

// Constructor

Counter(int a, int b){

counter = a;

limit = b;

}

// static function to increment

static increment(){

if(counter<limit)

nCounter+=1;

}

// Decrement function

void decrement(){

if(counter>0)

nCounter-=1;

}

int getValue(){

return counter;

}

static int nCounter;

int getNCounters(){

return nCounter;

}

};

// Initializa the static

int Counter::nCounter = 0;

4 0
3 years ago
When using the Common Internet File System (CIFS), which security model will require network users to have a user name and passw
hjlf

Answer:

User-level Security

Explanation:

User-level security allows the user to access resources on a network using a username and password. User-level security offers higher and greater security than share-level security, which does not require a password to access files.

User-level security allows the database user access and permission to resources.

4 0
2 years ago
Other questions:
  • What are the differences between levels 1, 2 and 3 cache memoroes??
    8·1 answer
  • You want to use a wireless keyboard and mouse with your laptop computer. which method should you use
    11·1 answer
  • Josh wants to convey his best wishes to johnathin for a meeting schedualed later diring the day. Which business documented would
    7·1 answer
  • What are expansion cards used for?​
    9·2 answers
  • What type of version of visual studio is the visual studio express
    8·1 answer
  • What is a close syllable
    5·2 answers
  • You received an email message stating that your mother's bank account is going to be forfeited if you do not respond to the emai
    6·1 answer
  • The process of sending a result back to another part of the program is
    14·1 answer
  • The area that we can see just after windows is started is subject​
    6·1 answer
  • One common command-line network utility tool is “netstat,” which displays which protocol is being used. It can review particular
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!