Java

posted by .

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.

  • Java -

    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);

Respond to this Question

First Name
School Subject
Your Answer

Similar Questions

  1. 6th grademath

    this is a word problem:the country of hoffnemath is holding its presidential election this week. there three candidates(a,b,c,) and each eligible voter can vote for two of them. the candidate with the most total votes wins the election. …
  2. java

    can anyone help me with this? I'm new to java! Write a program that will find the lowest common denominator of two numbers. The user will enter the two denominators, the program will output both the lowest common denominator and the
  3. java

    Write a java application that finds the smallest of several integers. Prompt the user for the number of integers that will be input, then prompt the user for that number of integers. Evaluate the integers to determine the smallest …
  4. programming

    Pseudocode - Create the logic for a program that continuously prompts a user for a numeric value until the user enters 0. The application passes the value in turn to a method that squares the number and to a method that cubes the number. …
  5. programming

    Create the logic for a program that continuously prompts a user for a numeric value until the user enters 0. The application passes the value in turn to a method that squares the number and to a method that cubes the number. The program …
  6. programming pseudocode

    Create the logic for a program that continuously prompts a user for a numeric value until the user enters 0. The application passes the value in turn to a method that squares the number and to a method that cubes the number. The program …
  7. programming

    Write a program which allows user to enter 10 student names and scores for Java programming 1 and Java programming 2. Allow user to choose which course they want to enter the record for. Use the loop to ask input from user. The program …
  8. java.please help

    Write a Java program that prompts the user for a string. If the string entered by the user does not start with Hello and does not end with a digit, print incorrect and re-prompt the user. Otherwise, print Thank you.
  9. java programming

    the learner is asked to write a program using java with user input that caculate and displays, the number of months it will take the user to save an amount of money. the user must enter the
  10. Ic

    Write an application that prompts the user for two integers and then prompts the user to enter an option as follows: 1 to add the two integers, 2 to subtract the second integer from the first, 3 to multiply the integers, and 4 to divide …

More Similar Questions