Whats wrong with this code?

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2008
Posts: 21
Reputation: AirmanTheGreat is an unknown quantity at this point 
Solved Threads: 0
AirmanTheGreat's Avatar
AirmanTheGreat AirmanTheGreat is offline Offline
Newbie Poster

Whats wrong with this code?

 
0
  #1
Aug 14th, 2008
Howdy, Im getting the "'.class expected" error and I dont know what to correct. The code is

  1. import java.io.*;
  2. public class TeamHeight
  3. {
  4. public static void main (String[] args)
  5. throws IOException
  6. {
  7. double[] height = new double[11];
  8. double sum = 0;
  9. System.out.println ("The size of the array: " + height.length);
  10. for (int i = 0; i < height.length; i++)
  11. {
  12.  
  13. BufferedReader keyIn = new BufferedReader (new InputStreamReader(System.in));
  14. System.out.print ("Enter the height of the player: ");
  15. height = Double.parsedouble[](keyIn.readLine());
  16. System.out.print ("Player " + (i+1) + ": ");
  17. height[i] = Integer.parseInt(keyIn.readLine());
  18. sum = sum + height[i];
  19. }
  20. System.out.println ("The average height: " + (sum/11));
  21. System.out.println ();
  22. }
  23. }

Thanks
-Airman
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 807
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 110
darkagn's Avatar
darkagn darkagn is offline Offline
Practically a Posting Shark

Re: Whats wrong with this code?

 
0
  #2
Aug 14th, 2008
Have you compiled the code? That error usually relates to attempting to run a main method in a file that has not yet been compiled. If that was a compiler error, which line(s) give the error?
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 21
Reputation: AirmanTheGreat is an unknown quantity at this point 
Solved Threads: 0
AirmanTheGreat's Avatar
AirmanTheGreat AirmanTheGreat is offline Offline
Newbie Poster

Re: Whats wrong with this code?

 
0
  #3
Aug 14th, 2008
Originally Posted by darkagn View Post
Have you compiled the code? That error usually relates to attempting to run a main method in a file that has not yet been compiled. If that was a compiler error, which line(s) give the error?
Nope the code is not compiled. This error occurs when i attempt to compile it.

The error is at the line:


BufferedReader keyIn = new BufferedReader (new InputStreamReader(System.in));
System.out.print ("Enter the height of the player: ");
height = Double.parsedouble[](keyIn.readLine());
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 59
Reputation: Chaster is an unknown quantity at this point 
Solved Threads: 3
Chaster Chaster is offline Offline
Junior Poster in Training

Re: Whats wrong with this code?

 
0
  #4
Aug 14th, 2008
You should read a value, parse it put in your array and then start over. You cannot have parsedouble[] (actually the correct version is parseDouble(args)). When you read a value, you cannot convert it to an array. Just put it to the next location in your array.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 59
Reputation: Chaster is an unknown quantity at this point 
Solved Threads: 3
Chaster Chaster is offline Offline
Junior Poster in Training

Re: Whats wrong with this code?

 
1
  #5
Aug 14th, 2008
I mean:
  1. double temp = Double.parseDouble(keyIn.readLine());

an then:
  1. height[i] = temp;
Last edited by Chaster; Aug 14th, 2008 at 6:27 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 21
Reputation: AirmanTheGreat is an unknown quantity at this point 
Solved Threads: 0
AirmanTheGreat's Avatar
AirmanTheGreat AirmanTheGreat is offline Offline
Newbie Poster

Re: Whats wrong with this code?

 
0
  #6
Aug 14th, 2008
I changed the parse thing to

height = Double.parseDouble(KeyIn.readLine());

and now I get the error:

Incompatible types - found Double but expected Double[]
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 59
Reputation: Chaster is an unknown quantity at this point 
Solved Threads: 3
Chaster Chaster is offline Offline
Junior Poster in Training

Re: Whats wrong with this code?

 
0
  #7
Aug 14th, 2008
Originally Posted by AirmanTheGreat View Post
I changed the parse thing to

height = Double.parseDouble(KeyIn.readLine());

and now I get the error:

Incompatible types - found Double but expected Double[]
That's because height is an ARRAY but you here need a PRIMITIVE. You can use either a temp variable (as I described earlier), or try this: height[i] = Double.parseDouble(...);
Last edited by Chaster; Aug 14th, 2008 at 9:15 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 21
Reputation: AirmanTheGreat is an unknown quantity at this point 
Solved Threads: 0
AirmanTheGreat's Avatar
AirmanTheGreat AirmanTheGreat is offline Offline
Newbie Poster

Re: Whats wrong with this code?

 
0
  #8
Aug 15th, 2008
Thanks, Chaster!
Solved
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 649 | Replies: 7
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC