My prof has very very very very very specifically required this to function exactly as follows:
There are 2 classes. Die & dicecollection. This part of the project wants me to store multiple Die objects in an array, and this array HAS to be dicecollection. I can't make a representation i can't make a translation, etc. It very specifically has to be creating an array using the dicecollection class, then storing die inside that array. From everything i've googled and tested for the past hour and a half this simply seems to not exist. Every solution includes doing some sort of translation or transformation or representation of a corresponding array. Any answers greatly appreciated.
#Can an array of objects, itself be a different class than that of it's contents?
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
do you mean if type of array could be different than it's contents?
not the type of the array, the class. I have to have 2 classes. Die & Dicecollection. The array HAS to be an object of Dicecollection, and the array HAS to contain Die objects
yes, if i try to do this directly, the IDE tells me it cannot convert the types
show us what you have done, let me see
i'll make it more readable just a moment
DiceCollection[] lmao;
for (int i = 0; i < diceCount; i++){
Die die = new Die();
lmao[i] = die;
}
it tells me this. Type mismatch: cannot convert from Die to DiceCollection
can you share the question details?
I've also spoken to the prof and they confirmed yes it absolutely HAS to be an array object dicecollection and that array HAS to hold die objects
i don't think it means it has to be of type diceCollection
that class is just meant to be holder of array
and array is of type dice
how would i have a different class hold the array though? isn't that also against what they're saying "A DiceCollection object holds a set of Die objects in an array"
it could be a field which holds array of dies
so declare array inside the class of dicecollection, then edit that array in the main method?
is there a way you can confirm again with them? ask if array has to be of type Diecollection and hold object of type die
declare an array inside die collection? yes
i wish i could but it's due in 4 hours and it's 4am so they're definitely not awake. usually they do their emails around noon too.
pass array of integers to constructor of diecollection to initialize the no of sides each die has
i don't think it'll be end of world, if you got confused and tried your best
so the dicecollection class would create the array, but then wouldn't it be unable to adapt to the array size required?
i'll have to do some testing. Thanks a billion for the advice
from what i can read in questions, each die is supposed to have number of sides represented by an integer value
now how many sides each die will have, that's decided by what you pass in constructor of die collection
yes i can definitely do this. My biggest concern was that at that point i'm technically not having die objects held by a dicecollection object, but at the same time i kind of am? it's odd
your die collection is holding an array which is holding die objects so yea
yeah i see, it's layered but still technically in there
if you have more time, it's better to wait and hope someone else responds that's the best i got for now
anything is way more than nothing so again thanks a billion for the advice
yw 😄
wait to be clear @forest mason are you saying that i would actually have the die objects stored in an array that's in the dicecollection, or are you saying that i would have a representation of them? I'm assuming the latter but wanted to be sure
i meant the former
oh wait then nevermind i don't see how that'd be possible. In the end i would still run into the conversion issue, no?
not really, array would be of type die
collection just holds that array of type die
how though? That just gives me the same error
ohhhh are you talking about the util collection?
class DiceCollection {
Die[]
}
You are supposed to do something like that
(btw, oxford standard approved that dice can also be used as singular to avoid the troublesome word die)
yeah that's what i'm going towards but now i can't actually pass the user's input because for it to be in a constructor it can't be coming from something static. Unless i construct it within the same main app but then it's being constructed with an array that's just going to be replaced anyway because i need the array's size BEFORE it's construction
God bless oxford, first the oxford comma, now this? Absolute W's
God bless all 3 of u i got it working... for now. But still working holy shit hell yeah ty a bunch