String inputVote;
int vote1 = 0;
int vote2 = 0;
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter your votes 10 times: ");
inputVote = keyboard.next();
if (inputVote.equalsIgnoreCase("Smith")){
vote1++;
}
if (inputVote.equalsIgnoreCase("Watson")){
vote2++;
}
inputVote = keyboard.next();
if (inputVote.equalsIgnoreCase("Smith")){
vote1++;
}
if (inputVote.equalsIgnoreCase("Watson")){
vote2++;
}
inputVote = keyboard.next();
if (inputVote.equalsIgnoreCase("Smith")){
vote1++;
}
if (inputVote.equalsIgnoreCase("Watson")){
vote2++;
}
inputVote = keyboard.next();
if (inputVote.equalsIgnoreCase("Smith")){
vote1++;
}
if (inputVote.equalsIgnoreCase("Watson")){
vote2++;
}
inputVote = keyboard.next();
if (inputVote.equalsIgnoreCase("Smith")){
vote1++;
}
if (inputVote.equalsIgnoreCase("Watson")){
vote2++;
}
inputVote = keyboard.next();
if (inputVote.equalsIgnoreCase("Smith")){
vote1++;
}
if (inputVote.equalsIgnoreCase("Watson")){
vote2++;
}
inputVote = keyboard.next();
if (inputVote.equalsIgnoreCase("Smith")){
vote1++;
}
if (inputVote.equalsIgnoreCase("Watson")){
vote2++;
}
inputVote = keyboard.next();
if (inputVote.equalsIgnoreCase("Smith")){
vote1++;
}
if (inputVote.equalsIgnoreCase("Watson")){
vote2++;
}
inputVote = keyboard.next();
if (inputVote.equalsIgnoreCase("Smith")){
vote1++;
}
if (inputVote.equalsIgnoreCase("Watson")){
vote2++;
}
inputVote = keyboard.next();
if (inputVote.equalsIgnoreCase("Smith")){
vote1++;
}
if (inputVote.equalsIgnoreCase("Watson")){
vote2++;
}
System.out.println("Smith votes: " + vote1);
System.out.println("Watson's votes: "+ vote2);
in Java how do you create a method that will prompt the user to type in 10 votes to determine a winner in a two candidate election?
Ex: Vote 10 times - Smith vs. Watson
User enters:
Watson
watson
wATson
Smith
SMITH
smiTh
watson
smith
watson
waTSoN
And then this should report that Watson wins 6 votes to 4 votes.
the names don't have to be Watson and Smith, any two names will do.
1 answer