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
Create a paper of at least 1,800 words describing the situation you selected and explaining the logic that would support an arra
sleet_krkn [62]

Answer:

I dont know about 1800 words but I sure can tell you abit about array

Explanation: Array in simple sense refers to a collection of similar data. It holds data which is homogeneous in nature, meaning they are all alike. The use of array provide a lot of advantages in the fields of computer programming. When you declare a variable for an array, you can store as much data as you wish in the same variable without having to declare many variables. A 2X2 dimensional array can also be used in programming which represents matrices as well. The search process in an array too is really convenient and time saving. Also in an array, accessing an element is very easy by using the index number.

6 0
2 years ago
In the previous project, you are storing the first name of the gamer. Write a phrase to the game right before the first word wit
hodyreva [135]

Answer:

Explanation:

Since the previous project code is not provided, what we can do is simply create the piece of code that does what the question is asking here and you can just add that to the previous project. I'll be assuming that the project was written in Java.

System.out.println("Are you ready to get started " + playerNameVariable + "?");

This line of code will ask the player if their "ready to get started?". It uses the playerNameVariable to state the name that the player had inputted previously. This line of code can be added to the previous project code right before the first word within the first paragraph of text

5 0
2 years ago
This project involves writing a program that encodes and decodes messages. The program should prompt the user to select whether
Lilit [14]

Answer:

See explaination

Explanation:

import java.util.Scanner;

public class EncodeDecodeMessage {

public static String encode(String str) {

String result = "";

char ch;

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

ch = str.charAt(i);

if(Character.isLowerCase(ch)) {

result += (char)('a' + (25-ch+'a'));

} else if(Character.isUpperCase(ch)) {

result += (char)('A' + (25-ch+'A'));

} else {

result += ch;

}

}

return result;

}

public static String decode(String str) {

return encode(str); // since the scheme is same, we can use encode for decode

}

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

System.out.print("1. Encode, 2. Decode. Enter your choice: ");

int choice = in.nextInt();

in.nextLine();

if(choice == 1) {

System.out.print("Enter sentence to encode: ");

String line = in.nextLine();

System.out.println("Encoded string is: " + encode(line));

} else if(choice == 2) {

System.out.print("Enter sentence to decode: ");

String line = in.nextLine();

System.out.println("Decoded string is: " + decode(line));

}

}

}

8 0
3 years ago
The requester of sensitive information should not receive access just because of his or her clearance, position, or rank. The re
JulsSmile [24]

Answer:

Need to know

Explanation:

Need to know is a policy or predetermined criterion by which the requester of an information is granted access to the requested information only when a valid need is establish and not just because of his or her clearance, position, or rank.  

7 0
3 years ago
What did the Lorax mean when he said i speak for the trees
kirill [66]

Answer:

The trees have no tongues, And the Lorax disapproves of the use of the Tree and the Thneed.

3 0
3 years ago
Other questions:
  • What is life all about?
    15·2 answers
  • All of the following are qualities of an aprenticeship except
    12·1 answer
  • Design and implement your own simple class to represent any household item of your choice (toaster, fan, hair dryer, piano ...)
    11·1 answer
  • Which of the following are types of home internet service? Check all that apply
    7·1 answer
  • Write a definition of the function printDottedLine, which has no parameters and doesn't return anything. The function prints to
    14·1 answer
  • What is the cell reference for row 22 and column B? __________<br><br> In excel
    5·1 answer
  • The response from a Google Form can be seen in how many ways?
    10·1 answer
  • Identify the following​
    9·1 answer
  • HELP PLEASE
    7·1 answer
  • Why should running your unit test suites not take a long time?A. Unit tests aren't that important, so less time should be spent
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!