-1

I cant seem to find what I have to put in to get this working. The beginning of my code in BleuJ looks like this.

public Aandeel(String code, String naam, double dividend, double[] tab)
{
    this.code = code;
    this.naam = naam;
    setDividend(dividend);
    waarden = new double[12];
    setWaarden(tab);
}

So I have no clue how I can fill in a good parameter for tab. I trief everything but I keep having these errors. ( Im talking about the last parameter)

enter image description here

PM 77-1
  • 11,712
  • 18
  • 56
  • 99
Durabrite
  • 5
  • 4

2 Answers2

0

I'm not super familiar with BlueJ but it looks like your array isn't being created right. 3.43[12] won't create a new array, you should try tab[0] = 3.43. You'll have to define the size somewhere above.

Another option would be to define it like new double[]{3.43}. Whatever suits your purposes better. I'd suggest taking a look at this question: How do I declare and initialize an array in Java?

Your array is out of bounds error is caused by i < waarden.length. You should be checking for i < tab.length. Something I would do is define waarden as new doulbe[tab.length]

so your entire class would look like:

public Aandeel(String code, String naam, double dividend, double[] tab)
{
    this.code = code;
    this.naam = naam;
    setDividend(dividend);
    waarden = new double[tab.length];
    setWaarden(tab);
}

public void setWaarden( double[] tab)
{
    for (int i = 0; i<tab.length; i++)
    {
         waarden[i] = tab[i]
    }
}
Community
  • 1
  • 1
BombSite_A
  • 280
  • 1
  • 3
  • 13
0

In double[] tab, you should pass values in the following format:-

{1.0,2.0,5.8,2.4,4.23,5.2}

which is the error , array required but double found

Deval Khandelwal
  • 3,187
  • 1
  • 24
  • 37
  • Hi, thanks for your answer. It seems to does it now. But I keep getting an ArrayIndexOutOfBoundsExeption error? – Durabrite Jan 17 '15 at 04:15
  • That is a different problem ... and most likely due to some other part of your code that you haven't shown us. But the message means that you have tried to index part of an array that does not exist. – Stephen C Jan 17 '15 at 04:18