Answer to Question #274715 in Java | JSP | JSF for jericho

Question #274715

Write a program for Presidential Elections, the user will enter his votes based on the code for each candidate. The program will add the total votes for each candidate and proclaim the winner whoever got the most number of votes. The user will stop in accepting votes if the user entered letter ‘Q’ to quit. Type ‘V’ to vote and ‘R’ to view the result. 


1
Expert's answer
2021-12-03T06:28:15-0500
import java.util.Scanner;

public class PresidentialElections {
  private ArrayList<String> votes;  

  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    bool state = true;
    while (state) {
      char c=s.nextChar();
      switch(c) {
        case 'R':
          result();
          break;
        case 'V':
          vote(s);
          break;
        case 'Q':
          state = false;
      }
    }
  }

  private static void result() {
    // impl...
  }

  private static void vote(Scanner s) {
    // impl...
  } 
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS