Asked by Cheunology
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.
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.
Answers
Answered by
Anonymous
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);
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);
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.