File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes New to this stuff Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "New to this stuff" Watch "New to this stuff" New topic

New to this stuff

Thomas Kelley

Joined: Mar 14, 2012
Posts: 2
Ok so I am new to this forum.. and somewhat new to java ..
I have this program that I am running and for some reason it is missing the first part of it.
it odes not ask for the age sex, voter party or who is voted for.
can someone please help me out with this.

Thank you

Matthew Brown

Joined: Apr 06, 2010
Posts: 4543

Hi Thomas. Welcome to The Ranch!

Have a closer look at these two lines:

In particular, look at the "Y"...
Thomas Kelley

Joined: Mar 14, 2012
Posts: 2
Thank you for your help..
that worked..

but its not keeping trak of the the Male or fenale tally or the votes for Santorum Romney or paul.. any thoughts?
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

When you are comparing the contents of two strings, don't use the == operator. That just checks whether its operands are the same String object, which isn't helpful because two different String objects can contain the same text.

You already knew to use the equals() method elsewhere. Use it everywhere you compare two String objects.
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

The male or female tally is the same issue that you were having with "yes" vs "Yes",

you prompt the user to enter their sex:

Note "Male" or "Female" above

Then you test the sex condition using:

I think what you actually want to use is that way no matter what case you enter: "male", "Male", "mAlE", or "MALE" it will still return true.


"If the facts don't fit the theory, get new facts" --Albert Einstein
Winston Gutkowski

Joined: Mar 17, 2011
Posts: 8942

Thomas Kelley wrote:can someone please help me out with this.

I think everybody else has pretty much told you the procedural problems, but the basic problem with your program to me is that it is procedural. Java is an Object (or, if you like, Class) oriented language, and Strings usually make bad substitutes for other classes.

My tip: Have a think about creating Party and Sex classes (no snickering in the back row).


Bats fly at night, 'cause they aren't we. And if we tried, we'd hit a tree -- Ogden Nash (or should've been).
Articles by Winston can be found here
I agree. Here's the link:
subject: New to this stuff
It's not a secret anymore!