required: double[] found: double
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
-
1 -
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
.. I changed getScoreNum variable to an array as such
and got the following
what did I do wrong
??-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I See what I did wrong and fixed it .. Thanks for the Help ..
if I faced another problem I'll come back 
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
private int JudgeNum;
do I need intilize it ? and where ?
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
This will create and initialize
or
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
.. 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
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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....
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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..
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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?
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
).
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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..
| Screaming fools! It's nothing more than a tiny ad: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |







