So, this is the question - Write a program that accepts the names of three political parties and the number of votes each received in the last mayoral election. Display the percentage of the vote each party received.   This is the code I have so far but I am honestly stuck and don't think this is correct -  import java.util.Scanner; class ElectionStatistics {     public static void main(String[] args) {         int vote1, vote2, vote3;         String party1, party2, party3;         int total;         double pct1, pct2, pct3;         Scanner input = new Scanner(System.in);         System.out.println("Enter name for the first party: ");         party1 = input.nextLine();         System.out.println("Enter votes recieved: ");         vote1= input.nextInt();         input = nextLine();           System.out.println("Enter name for the second party: ");         party2 = input.nextLine();         System.out.println("Enter votes recieved: ");         vote2= input.nextInt();         input = nextLine();           System.out.println("Enter name for the third party: ");         party3 = input.nextLine();         System.out.println("Enter votes recieved: ");         vote3= input.nextInt();         input = nextLine();     } }

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter4: Selection Structures
Section: Chapter Questions
Problem 14PP
icon
Related questions
Question

So, this is the question - Write a program that accepts the names of three political parties and the number of votes each received in the last mayoral election. Display the percentage of the vote each party received.

 

This is the code I have so far but I am honestly stuck and don't think this is correct - 

import java.util.Scanner;
class ElectionStatistics {
    public static void main(String[] args) {
        int vote1, vote2, vote3;
        String party1, party2, party3;
        int total;
        double pct1, pct2, pct3;
        Scanner input = new Scanner(System.in);
        System.out.println("Enter name for the first party: ");
        party1 = input.nextLine();
        System.out.println("Enter votes recieved: ");
        vote1= input.nextInt();
        input = nextLine();
          System.out.println("Enter name for the second party: ");
        party2 = input.nextLine();
        System.out.println("Enter votes recieved: ");
        vote2= input.nextInt();
        input = nextLine();
          System.out.println("Enter name for the third party: ");
        party3 = input.nextLine();
        System.out.println("Enter votes recieved: ");
        vote3= input.nextInt();
        input = nextLine();
    }
}
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr