Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Avery Jerauld
Greenhorn
Posts: 28
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15277
38
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You forgot a + in lines 11 and 18. Look closely at the lines.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12122
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Avery Jerauld
Greenhorn
Posts: 28
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48932
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic