• Post Reply Bookmark Topic Watch Topic
  • New Topic

required: double[] found: double  RSS feed

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello every one sorry for the inconvenience .. I'm new here and I was hoping to find anyone to help me with my Java Problem..
it is a school assignment and I'm building it as I go. so I got stumped in this problem..

it asks..

boolean recordScore(double score)
Adds a score to the end of the array, provided that the DivingScore array has fewer than the maximum of 11 scores already stored. Returns true is successful, false otherwise.

so I wrote the following in the main class..



.. I run it .. everything is okay..

I go to the test program [Note: Test Program should not be ever changed] and I run it .. and I get

DivingScoreTest.java:16: error: incompatible types
a = luke.getScore();
^
required: double[]
found: double
1 error

.. I'm confused on what to fix

here is the test Program..



Thanks for any Help you provide
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Simply, your test program is expecting the getScore() method to return a double array. Your getScore() method returns a double (ie. not a double array).

If the test program isn't allowed to change, then you need to change your getScore() method to return a double array instead.

Henry

 
Ali Al Khulaifi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see ..

I changed getScoreNum variable to an array as such



and got the following



what did I do wrong ??
 
Ali Al Khulaifi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never mind... I See what I did wrong and fixed it ..

Thanks for the Help .. if I faced another problem I'll come back
 
Ali Al Khulaifi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for the bother but it seems I'm bumped into another problem..

I got this error when I ran the test program ..



the 1st line points at..



the 2nd one is here..



Can anyone explain what am I doing wrong ?? Thank you in advance
 
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you initialized "judgeScore" array variable and reference variable "luke" before using it?
 
Ali Al Khulaifi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no.. I only declared inside the main class..

private int JudgeNum;

do I need intilize it ? and where ?
 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you some more code to tell you correctly? but if you are testing then you can do it in main.
 
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You appear to be rushing through your code and rushing through this discussion. You were asked whether you had initialised judgeScore and you told us you had only declared judgeNum. Take it easy and take time to read and understand the responses. A likely cause of that Exception is that you declared judgeScore and forgot to initialise it, so that is what you need to look for. You might get other problems about judgeNum but we haven't seen anything yet, so we shall presume you are all right there.

If you are programming you need to be methodical. Remember the computer will take you literally whatever you say. So you need to write literally what you want. And that takes time and thought.

We presume you managed to turn judgeScore into an array so you get rid of the original error.
 
Ali Al Khulaifi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.. I was able to finish coding the whole prog, except understanding about initializing ... can see what I did wrong and help me fix it ? I appreciate everyones work in helping me understand

 
Saloon Keeper
Posts: 3336
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This will create a reference to an array (uninitialized), but not the array itself.

This will create and initialize

or
 
Ali Al Khulaifi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks .. I have changed it .. and now when I run the program from the test program after removing the 2nd block .. I get the same error I posted before..

Ali Al Khulaifi wrote:



the 1st line points at..



the 2nd one is here..



Can anyone explain what am I doing wrong ?? Thank you in advance
 
Carey Brown
Saloon Keeper
Posts: 3336
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ali Al Khulaifi wrote:Thanks .. I have changed it .. and now when I run the program from the test program after removing the 2nd block .. I get the same error I posted before..
Can anyone explain what am I doing wrong ?? Thank you in advance

You'll have to mentally follow your code through to see if the array is initialized BEFORE you use it. Alternatively, if you're using an IDE, you can run it in debug mode with a break point on the line where you initialize it.

Edit: If you're STILL stuck you'll have to re-post the code in its entirety so that we can see where you think you're initializing it.
 
Ali Al Khulaifi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:
You'll have to mentally follow your code through to see if the array is initialized BEFORE you use it. Alternatively, if you're using an IDE, you can run it in debug mode with a break point on the line where you initialize it.

Edit: If you're STILL stuck you'll have to re-post the code in its entirety so that we can see where you think you're initializing it.


I see.. Thank you.. I will see what I can do....
 
Ali Al Khulaifi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:You'll have to mentally follow your code through to see if the array is initialized BEFORE you use it. Alternatively, if you're using an IDE, you can run it in debug mode with a break point on the line where you initialize it.
Edit: If you're STILL stuck you'll have to re-post the code in its entirety so that we can see where you think you're initializing it.


I understand you want me to learn by my self and figure out what is wrong, and I thank you for that. I wanted help, you hinted out with capitals and advised to follow the flow of the codes. I couldn't ask more.

even though I'm still stuck in figuring out what is wrong with code, I will not ask again. I appreciate your last statement to help, and the advise you gave. thank you.

the code is there I will not repost because I fell it will be like spamming the forum. as I stated before in my previous post, I have changed the code base on your recommendation

I changed the..


to..


and got the error I posted previously when I ran the test program.

Carey Brown.. I'm sorry for anything bad that came out of me.. and I thank you for taking some of your time help me with my code.. again sorry..

 
Carey Brown
Saloon Keeper
Posts: 3336
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made the change you mention and now I get

In this code
You've declared an array of size 1 and because an array index is 0 based, the only valid index would be 0, which is not what you've got.

Edit: In this piece of code, why is getScoreNum an array at all?

 
Carey Brown
Saloon Keeper
Posts: 3336
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In line 1 you initialize array 'a', but in line 2 you overwrite it with the results from getScore(). Hence, the initialization is unnecessary in this example.
 
Carey Brown
Saloon Keeper
Posts: 3336
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. Sorry for the capitalization. I was trying to understand what your code looked like without actually being able to see it. Your explanation of the code modification you made is what I needed.
 
Campbell Ritchie
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my opinion you should initialise every field to a sensible value in the constructor. Go through every constructor and check whether that array is initialised there. If not, why not? Then check whether your array is reinitialised anywhere. If you are reinitialising the array, why? If you are not reinitialising or reassigning the array, that is a good sign ().
 
Ali Al Khulaifi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the Reply and I deeply apologise for the late reply..
I was able to talk to the instructor and get to correct the mistake in the code..
here is the code with Java doc for your view..


 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!