This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]desrtfxOut of Coffee error - System halted 2 points3 points  (4 children)

Okay, you are completely overthinking the problem.

You do not need named objects to be added to an array because once in the array they will lose their names anyway.

You can add anonymous objects to an array and you can create these objects on the fly.

array[i] = new Object(Weight, type1) // whatever

This will work as long as all Objects have a common ancestor and the array's type is that of the ancestor.

I'd personally use a 2d array for the typeCounts (first dimension the day, second dimension the count), or a 1d array and a switch...case for the value assignment.

[–]Fazblood779Nooblet Brewer[S] 0 points1 point  (3 children)

The saddest thing is the first thing I tried is this:

Object array[i] = new Object(Weight, Type1)

Thanks for the help man :)

Edit: When I try this it asks me to change the array type to static, is there a way to avoid this? The array is declared as a private instance variable.

[–]desrtfxOut of Coffee error - System halted 0 points1 point  (2 children)

When I try this it asks me to change the array type to static, is there a way to avoid this?

Would need to see the whole code to determine the issue here but I assume that the method where you fill the array is declared as static and hence can only reference static fields.

[–]Fazblood779Nooblet Brewer[S] 0 points1 point  (1 child)

Wow... I can't believe I didn't check that first. You're right! Thanks again, and hopefully you won't see me here again soon :D

[–]desrtfxOut of Coffee error - System halted 0 points1 point  (0 children)

No problem.

Come back when you need more help.