aspose file tools*
The moose likes Beginning Java and the fly likes First program by myself. Need help on one error please! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "First program by myself. Need help on one error please!" Watch "First program by myself. Need help on one error please!" New topic
Author

First program by myself. Need help on one error please!

Avery Jerauld
Greenhorn

Joined: Aug 15, 2011
Posts: 28

You may remember from earlier this week, I was asking for help on a program that had to do with weight and height. Here's the program:





Everything works just fine, but the problem I have is that it says:

"')' expected ----- line 11"
"')' expected ----- line 18"



Those are the "System.out.println" lines. But I can't find where to put them. Help?

And I do know how you enter your height is a little unorthodox, but it should work just fine. Haha.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14150
    
  18

You forgot a + in lines 11 and 18. Look closely at the lines.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11314
    
  16

remember that the compiler is pretty dumb. It makes a 'best guess' as to what and where the problem is, but it won't always be correct.

if you get stuck, what I would recommend doing it comment out the bad line. then, try rebuilding it a piece at a time. I'd do it like this:



if that works add the next piece

etc.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Avery Jerauld
Greenhorn

Joined: Aug 15, 2011
Posts: 28

Jester was right. But thank you for that tip on making the comment and remaking the line. That will help in the future.

But now that I've fixed that, twelve more errors popped up. They seem to be the same thing, but I'm clueless on what to do. :/

Every "scanner" (not "Scanner"), "nextInt", "inches", and the "/" in



is red. It says:
1) "Cannot find symbol class scanner" for the red "scanner"
2) "Cannot find symbol variable inches" for the red "inches"
3) "Operator / cannot be applied to <nulltype>,int" for the red "/"
4) "weight is already defined in main (java.lang.String[])"
5) "height is already defined in main (java.lang.String[])"

I'm thinking I have to make the second part of the code (finding the height and weight for the man) a different section because weight is calculated differently for that part. But I'm completely clueless. Can anyone help?
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4392
    
    8

You need to be more careful when declaring variables:

- Line 6 - it's Scanner, not scanner. Java is case-sensitive, and the convention is that class names should start with a capital
- That means that everywhere else you use scan, it's undefined.
- Line 8 (and onward), you're using inches, but it isn't declared anywhere

Once you've sorted that out, you'll hit another snag - on lines 13, 16 and 17 you're declaring variables that will have already been declared.
Avery Jerauld
Greenhorn

Joined: Aug 15, 2011
Posts: 28

Matthew Brown wrote:You need to be more careful when declaring variables:

- Line 6 - it's Scanner, not scanner. Java is case-sensitive, and the convention is that class names should start with a capital
- That means that everywhere else you use scan, it's undefined.
- Line 8 (and onward(, you're using inches, but it isn't declared anywhere

Once you've sorted that out, you'll hit another snag - on lines 13, 16 and 17 you're declaring variables that will have already been declared.




Dude, you're seriously the best. I don't know what it was about your post but it just made it all click for me. I changed the variables to manHeight, manWeight, womanHeight, and womanWeight to keep them separated. I then took out the second "Scanner scan=new Scanner".

I just have to change one thing about what the output says and I'm done. Thank you ever so much.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
Avery Jerauld wrote:Jester was right. . . .
Programming is the one place where there is a real use for "writing lines"

I think 2019 is right for ’; I looked it up on Unicode.
Avery Jerauld
Greenhorn

Joined: Aug 15, 2011
Posts: 28

Campbell Ritchie wrote:
Avery Jerauld wrote:Jester was right. . . .
Programming is the one place where there is a real use for "writing lines"

I think 2019 is right for ’; I looked it up on Unicode.


Haha. Sorry about that. I was trying to remember multiple names and ended up only putting his name in the post, and I still messed that up XD

But my program's working perfectly. Thank you all!
Gaurav Raje
Ranch Hand

Joined: Jul 23, 2010
Posts: 136
Avery Jerauld wrote:
Everything works just fine, but the problem I have is that it says:

If it doesnt compile, how does everything work fine
Remember, if it doesnt compile, just because it shows just 1 error doesnt mean there are no more....

1 error in compilation = 100 errors in compilation... You can never guess without having debugged completely.
else the halting problem would have been decidable.

There are many instances when you forget a } and it shows like 100 errors. You add that and all of dem disappear.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: First program by myself. Need help on one error please!