Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I'm lost, need help figuring what todo?

 
mike statham
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Been Fix thanks to you all!

Reposed the old code, after I learn I shouldn, sry agian

 
Manoj Kumar Jain
Ranch Hand
Posts: 198
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the "key" ??
 
Marco Galea
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you haven't declared "key" anywhere in your code that's why it's throwing that error. If you want to read the nextDouble you should use the reference you created for the Scanner object i.e. "scan"



also i don't actually get the use of the do-while in the first place. i think you could have done for example



but you'll still will have a problem cause you need to advance the scanner to the next new line and calculate the average for each "person" and print
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may want to scan each whole line from the file as a single String object, split() the line into an array of String objects at the " " (space), then parse the resulting String objects into the desired forms ( String, Double, Double, Double ). Repeat while lines exist in the file.

This approach works well if you're then creating objects from the data, say a Student object, in which to store the results.
 
Winston Gutkowski
Bartender
Pie
Posts: 10430
63
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greg Brannon wrote:You may want to scan each whole line from the file as a single String object, split() the line into an array of String objects at the " " (space), then parse the resulting String objects into the desired forms ( String, Double, Double, Double ).

Totally agree. I dislike Scanner intensely.

Winston
 
Stephan van Hulst
Bartender
Pie
Posts: 5912
66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for hijacking, but how come? I think Scanner is a wonderful class.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:Sorry for hijacking, but how come? I think Scanner is a wonderful class.


I've just never liked the color scheme.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic