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.
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...
}
}
Comments
Leave a comment