Spread the word.

Share the link on social media.

Share
  • Facebook
Have an account? Sign In Now

Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here
Sign InSign Up

SIKSHAPATH

SIKSHAPATH Navigation

  • Home
  • Questions
  • Blog
    • Computer Science(CSE)
    • NPTEL
    • Startup
  • Shop
    • Internshala Answers
Search
Ask A Question

Mobile menu

Close
Ask A Question
  • Home
  • Questions
  • Blog
    • Computer Science(CSE)
    • NPTEL
    • Startup
  • Shop
    • Internshala Answers
Home/ Questions/Q 4672
Next
In Process

SIKSHAPATH Latest Questions

Kalpana
  • 0
  • 0
Kalpana
Asked: November 16, 20212021-11-16T10:40:43+05:30 2021-11-16T10:40:43+05:30In: Programming Language

Election day

  • 0
  • 0

Problem 29: Election day
It’s almost election day and the election officials need a program to help tally
election results. There are two candidates for office—Polly Tichen and Ernest
Orator. The program’s job is to take as input the number of votes each candidate
received in each voting precinct and find the total number of votes for each. The
program should print out the final tally for each candidate—both the total
number of votes each received and the percent of votes each received. Clearly
a loop is needed. Each iteration of the loop is responsible for reading in the votes
from a single precinct and updating the tallies. A skeleton of the program is in
the file Election.java. Open a copy of the program in your text editor and do the
following.
1. The election officials want more information. They want to know how many
precincts each candidate carried (won). Add code to compute and print this. You
need three new variables: one to count the number of precincts won by Polly,
one to count the number won by Ernest, and one to count the number of ties.
Test your program after adding this code.

question
  • 2 2 Answers
  • 325 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    2 Answers

    • Voted
    • Oldest
    • Recent
    1. I'M ADMIN
      I'M ADMIN
      2021-11-18T00:22:42+05:30Added an answer on November 18, 2021 at 12:22 am
      
      package com.explain;
      
      import java.util.Scanner;
      
      class Election{
          public static void main(String[] args) {
              int votesForPolly;
              int votesForErnest;
              int totalErnest;
              String responce;
      
              Scanner scan = new Scanner(System.in);
      
              System.out.println();
              System.out.println("Election Day Vite Counting Program");
              System.out.println();
      
              int x;
              votesForPolly =0;
              votesForErnest=0;
              totalErnest=0;
      
              while(true){
                  totalErnest++;
                  System.out.println("Whom do you want?\n1.Polly\n2.Ernest\n(1/2):");
                  x = scan.nextInt();
      
                  if(x==1){
                      votesForPolly++;
                  }
                  else if (x==2) {
                      votesForErnest++;
                  }
      
                  System.out.println("Are there more precincts to report(y/n):");
                  responce = scan.next();
                  if(responce.toUpperCase().equals("N")){
                      break;
                  }
              }
      
              System.out.println("Total votes for Polly:"+votesForPolly);
              System.out.println("Total votes for Ernest:"+votesForErnest);
              System.out.println("Total votes :"+totalErnest);
      
              float ernestPer = (votesForErnest*100/totalErnest);
              float pollyPer = (votesForPolly*100/totalErnest);
      
              System.out.println("Ernest:"+ernestPer+"%");
              System.out.println("Polly:"+pollyPer+"%");
      
      
              if(votesForErnest>votesForPolly){
                  System.out.println("Ernest won by:"+(votesForErnest-votesForPolly)+"more precincts/votes");
              }
              else if (votesForErnest<votesForPolly) {
                  System.out.println("Polly won by:"+(votesForPolly-votesForErnest)+"more precincts/votes");
              }
              else if(votesForErnest==votesForPolly){
                  System.out.println("It was a tie with 50% for both");
              }
          }
      }
      
      
        • 0
      • Reply
      • Share
        Share
        • Share on WhatsApp
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
    2. MAYANK_76
      MAYANK_76
      2021-11-26T19:32:47+05:30Added an answer on November 26, 2021 at 7:32 pm
      package com.explain;
      
      import java.util.Scanner;
      
      class Election{
      public static void main(String[] args) {
      int votesForPolly;
      int votesForErnest;
      int totalErnest;
      String responce;
      
      Scanner scan = new Scanner(System.in);
      
      System.out.println();
      System.out.println("Election Day Vite Counting Program");
      System.out.println();
      
      int x;
      votesForPolly =0;
      votesForErnest=0;
      totalErnest=0;
      
      while(true){
      totalErnest++;
      System.out.println("Whom do you want?\n1.Polly\n2.Ernest\n(1/2):");
      x = scan.nextInt();
      
      if(x==1){
      votesForPolly++;
      }
      else if (x==2) {
      votesForErnest++;
      }
      
      System.out.println("Are there more precincts to report(y/n):");
      responce = scan.next();
      if(responce.toUpperCase().equals("N")){
      break;
      }
      }
      
      System.out.println("Total votes for Polly:"+votesForPolly);
      System.out.println("Total votes for Ernest:"+votesForErnest);
      System.out.println("Total votes :"+totalErnest);
      
      float ernestPer = (votesForErnest*100/totalErnest);
      float pollyPer = (votesForPolly*100/totalErnest);
      
      System.out.println("Ernest:"+ernestPer+"%");
      System.out.println("Polly:"+pollyPer+"%");
      
      
      if(votesForErnest>votesForPolly){
      System.out.println("Ernest won by:"+(votesForErnest-votesForPolly)+"more precincts/votes");
      }
      else if (votesForErnest<votesForPolly) {
      System.out.println("Polly won by:"+(votesForPolly-votesForErnest)+"more precincts/votes");
      }
      else if(votesForErnest==votesForPolly){
      System.out.println("It was a tie with 50% for both");
      }
      }
      }
        • 0
      • Reply
      • Share
        Share
        • Share on WhatsApp
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn

    Leave an answer
    Cancel reply

    You must login to add an answer.

    Forgot Password?

    Need An Account, Sign Up Here

    Sidebar

    store ads

    Stats

    • Questions 1k
    • Answers 1k
    • Posts 149
    • Best Answers 89
    • This Free AI Tool Translates Entire Books in Minute !
    • AI News: 🎬 Hollywood’s AI Studios, 🎓 OpenAI’s Latest Gift to Educators, 🚚 Class8 Bags $22M, 🧠 Google Gemini’s Memory Upgrade
    • AI NEWS: Legal Action Against OpenAI, $16M Paid, & Elon Musk’s Praise from Investor 🤖💰📑 | AI Boosts Cloud Seeding for Water Security 🌱💧
    • AI News: 🎬AI Video Tool Scam Exposed🤯, 🛰️ AI-Powered Drones to Ukraine 😱, Google’s $20M AI Push, Sam Altman Joins SF’s Leadership Team
    • AI News: 🤝 Biden Meets Xi on AI Talks, 💡 Xavier Niel’s Advice for Europe, ♻️ Hong Kong’s Smart Bin Revolution, 🚀 AI x Huawei

    Explore

    • Recent Questions
    • Questions For You
    • Answers With Time
    • Most Visited
    • New Questions
    • Recent Questions With Time

    Footer

    SIKSHAPATH

    Helpful Links

    • Contact
    • Disclaimer
    • Privacy Policy Notice
    • TERMS OF USE
    • FAQs
    • Refund/Cancellation Policy
    • Delivery Policy for Sikshapath

    Follow Us

    © 2021-24 Sikshapath. All Rights Reserved

    Insert/edit link

    Enter the destination URL

    Or link to existing content

      No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.