473,582 Members | 3,083 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Java Programming Help

5 New Member
Hello to all. I am having difficulty trying to do this Java project using Eclipse. The following is what I have to do.

Election Day It's almost election day and the election officials need a program to help tally election results. There are two candidates for office -- Polly Tichen and Ernest Orator. The program's job is to take as input the number of votes each candidate received in each voting precinct and find the total number of votes for each. The program should print out the final tally for each candidate -- both the total number of votes each received and the percent of votes each received. Clearly a loop is needed. Each iteration of the loop is responsible for reading in the votes from a single precinct and updating the tallies. Your code should have the following:

1) Add the code to control the loop. You may use either a while loop or a do...while loop. The loop must be controlled by asking the user whether or not there are more precincts to report (that is, more precincts whose votes need to be added in). The user should answer with the character y or n though your program should also allow uppercase repsonses. The variable response (type char) has already been declared.

2)Add the code to read in the votes for each candidate and find the total votes. Note that variables have already been declared for you to use. Print out the totals and the percentages after the loop.

3) Test your program to make sure it is correctly tallying the votes and finding the percentages AND that the loop control is correct (it goes when it should and stops when it should).

4)The election officials want more information. They want to know how many precincts each candidate carried (won). Add code to compute and print this. You need three new variables: one to count the number of precincts won by Polly, one to count the number won by Ernest, and one to count the number of ties. Test your program after adding this code.

*************** *************** *************** ***************

This is the skeleton of the code:

// *************** *************** *************** *************** ***
// Election.java
//
// This file contains a program that tallies the results of
// an election. It reads in the number of votes for each of
// two candidates in each of several precincts. It determines
// the total number of votes received by each candidate, the
// percent of votes received by each candidate, the number of
// precincts each candidate carries, and the
// maximum winning margin in a precinct.
// *************** *************** *************** *************** **
Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner;
  2.  
  3. public class Election
  4. {
  5.     public static void main (String[] args)
  6.     {
  7.     int votesForPolly;  // number of votes for Polly in each precinct
  8.     int votesForErnest; // number of votes for Ernest in each precinct
  9.     int totalPolly;     // running total of votes for Polly
  10.     int totalErnest;    // running total of votes for Ernest
  11.     String response;      // answer ('y' or 'n') to the "more precincts" question
  12.  
  13.     System.out.println ();
  14.     System.out.println ("Election Day Vote Counting Program");
  15.     System.out.println ();
  16.  
  17.     // Initializations
  18.  
  19.     // Loop to "process" the votes in each precinct
  20.  
  21.     // Print out the results
  22.     }
  23. }
  24.  
*************** *************** *************** ***************

And this is the code I have:

*************** *************** *************** *************** ***
// Election.java
//
// This file contains a program that tallies the results of
// an election. It reads in the number of votes for each of
// two candidates in each of several precincts. It determines
// the total number of votes received by each candidate, the
// percent of votes received by each candidate, the number of
// precincts each candidate carries, and the
// maximum winning margin in a precinct.
// *************** *************** *************** *************** **

Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner;
  2.  
  3. public class Election
  4. {
  5.     public static void main (String[] args)
  6.     {
  7.     int votesForPolly;  // number of votes for Polly in each precinct
  8.     int votesForErnest; // number of votes for Ernest in each precinct
  9.     int totalPolly;     // running total of votes for Polly
  10.     int totalErnest;    // running total of votes for Ernest
  11.     String response;    // answer (y or n) to the "more precincts" question
  12.  
  13.     Scanner scan = new Scanner(System.in);
  14.  
  15.     System.out.println ();
  16.     System.out.println ("Election Day Vote Counting Program");
  17.     System.out.println ();
  18.     // Initializations
  19.  
  20.     // Loop to "process" the votes in each precinct
  21.     {System.out.println ("Enter Votes? Enter Y or N");
  22.     response=scan.next().toUpperCase();
  23.     if (response.equals("Y"));
  24.     {response=Yes)    
  25.     System.out.println ("Enter votes for Polly:");
  26.     votesForPolly=scan.nextInt();
  27.     totalPolly=totalPolly+ votesForPolly;
  28.     System.out.println ("Enter votes for Ernest:");
  29.     votesForErnest=scan.nextInt();
  30.     totalErnest=totalErnest+ votesForErnest;}
  31.     System.out.println ("Enter another District? Enter Y or N");
  32.     response=scan.next().toUpperCase();    }
  33.     else 
  34.  
  35. {    response=0
  36.  
  37.     while (response =1)    
  38.         }
  39.     // Print out the results
  40.     System.out.println ("Total votes for Polly is: " + totalPolly);
  41.     System.out.println ("Total votes for Ernest is: " + totalErnest);    
  42.     }
  43. }
*************** *************** *************** ***************

I need help in that I do not have the initialization step missing in my code, and the following errors show up in my code:

Exception in thread "main" java.lang.Error : Unresolved compilation problems:
Yes cannot be resolved
Syntax error on token ")", ; expected
Syntax error on token "else", delete this token
Syntax error, insert ";" to complete BlockStatements
Type mismatch: cannot convert from int to String
Syntax error on token ")", EmptyStatement expected after this token


Please help me eliminate the errors I have in my code and the steps I need to tame to get my project to work.

Thank you.
Apr 13 '08 #1
1 2001
r035198x
13,262 MVP
Just look at the error messages one at a time. They usually give you some hints as well.
Apr 14 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
3001
by: inquirydog | last post by:
Hello- I, the inquirydog, would like to solicit suggestions for a new web page I am making: I am creating a simple website that will translate concepts between windows os's, Linux, and the Java language with all of its related technologies. The website is at http://members.dslextreme.com/users/inquirydog, and is a mock-version of the...
73
7952
by: RobertMaas | last post by:
After many years of using LISP, I'm taking a class in Java and finding the two roughly comparable in some ways and very different in other ways. Each has a decent size library of useful utilities as a standard portable part of the core language, the LISP package, and the java.lang package, respectively. Both have big integers, although only...
6
3857
by: Alan Brown | last post by:
As a newbie I would like to ask what the difference in application (not details) is between C++ and Java. In what situations would you use C++ in preference to Java and vice versa? I am not asking for personal opinions on which is the *best* language :) Alan.
55
45963
by: Elijah | last post by:
I have read many of the topics on learning C++ or Java first. It seems like everyone says something different. I would like to know if I should learn C++ or Java. First a little about myself. I know PHP, BASIC, and of course HTML. I'll be 15 years old in September. I am interested in programming GUI applications. I am also interested in...
11
9230
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in C++. I find my self sometimes, trying Object app = Object(); Object *app = Object(); Object app = new Object();
1
9613
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the...
2
6942
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of attending interviews. If you own a company best way to judge if the candidate is worth of it. http://www.questpond.com/InterviewRatingSheet.zip
5
6271
by: r035198x | last post by:
Setting up. Getting started To get started with java, one must download and install a version of Sun's JDK (Java Development Kit). The newest release at the time of writting this article is JDK 6 downloadable from http://java.sun.com/javase/downloads/index.jsp. I will be using JDK 5(update 8)
0
7809
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8312
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7920
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8183
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6569
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5685
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5366
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3809
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2312
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.