Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Errors I don't know how to fix java beginner I need help ASAP

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Errors I don't know how to fix java beginner I need help ASAP

    I have an assignment for a class I need to complete and I have finished the code but don't know how to fix two errors I have.
    import java.util.Scanner;

    public class Election
    {
    public static void main (String[] args)
    {
    int votesForPolly; // number of votes for Polly in each precinct
    int votesForErnest; // number of votes for Ernest in each precinct
    int totalPolly; // running total of votes for Polly
    int totalErnest; // running total of votes for Ernest
    String response; // answer (y or n) to the "more precincts" question

    Scanner scan = new Scanner(System.in);

    System.out.println ();
    System.out.println ("Election Day Vote Counting Program");
    System.out.println ();
    // Initializations

    // Loop to "process" the votes in each precinct
    {System.out.println ("Enter Votes? Enter Y or N");
    response=scan.next().toUpperCase();
    if (response.equals("Y"))
    response="Yes";
    System.out.println ("Enter votes for Polly:");
    votesForPolly=scan.nextInt();
    totalPolly=totalPolly+ votesForPolly;
    System.out.println ("Enter votes for Ernest:");
    votesForErnest=scan.nextInt();
    totalErnest=totalErnest+ votesForErnest;}
    System.out.println ("Enter another District? Enter Y or N");
    response=scan.next().toUpperCase(); }
    else

    {
    response = 0;
    while (response == 1)
    }
    // Print out the results
    System.out.println ("Total votes for Polly is: " + totalPolly);
    System.out.println ("Total votes for Ernest is: " + totalErnest);
    }
    }import java.util.Scanner;

    public class Election
    {
    public static void main (String[] args)
    {
    int votesForPolly; // number of votes for Polly in each precinct
    int votesForErnest; // number of votes for Ernest in each precinct
    int totalPolly; // running total of votes for Polly
    int totalErnest; // running total of votes for Ernest
    String response; // answer (y or n) to the "more precincts" question

    Scanner scan = new Scanner(System.in);

    System.out.println ();
    System.out.println ("Election Day Vote Counting Program");
    System.out.println ();
    // Initializations

    // Loop to "process" the votes in each precinct
    {System.out.println ("Enter Votes? Enter Y or N");
    response=scan.next().toUpperCase();
    if (response.equals("Y"))
    response="Yes";
    System.out.println ("Enter votes for Polly:");
    votesForPolly=scan.nextInt();
    totalPolly=totalPolly+ votesForPolly;
    System.out.println ("Enter votes for Ernest:");
    votesForErnest=scan.nextInt();
    totalErnest=totalErnest+ votesForErnest;}
    System.out.println ("Enter another District? Enter Y or N");
    response=scan.next().toUpperCase(); }
    else

    {
    response = 0;
    while (response == 1)
    }
    // Print out the results
    System.out.println ("Total votes for Polly is: " + totalPolly);
    System.out.println ("Total votes for Ernest is: " + totalErnest);
    }
    }

    the errors I get are
    Error: Syntax error on token "else", { expected
    and
    Error: Syntax error on token ")", EmptyStatement expected after this token
    any help would be appriciated


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,146
    My Mood
    Mellow
    Thanks
    187
    Thanked 660 Times in 647 Posts

    Default Re: Errors I don't know how to fix java beginner I need help ASAP

    Please read this topic to learn how to post code in code or highlight tags and other useful info for newcomers. After learning about tags, please edit your post.

    While you're editing your posted code, review your indenting and see if your else statement immediately follows the if it belongs to.

Similar Threads

  1. Help with my code for homework assignment, I don't know how to fix it!
    By maxman190 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: October 19th, 2013, 03:01 AM
  2. I keep getting an error message but I don't know how to fix this!
    By mpagudelo in forum What's Wrong With My Code?
    Replies: 2
    Last Post: September 12th, 2013, 01:56 AM
  3. Replies: 1
    Last Post: June 9th, 2012, 11:29 AM
  4. try-catch block reports to have an Error that I don't know how to fix
    By baraka.programmer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 24th, 2011, 06:27 AM
  5. Can't fix my own errors
    By mrroberts2u in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 14th, 2011, 09:20 AM