Could someone please explain to me why we have to create the deck object twice in order for this piece of code to work? From what I can tell, it looks as if the first Card object is only used for the 'for' condition, and is replaced by the new card object?
This is an example from my textbook. The book doesn't talk about this portion. I am not sure how to phrase this question to use google, either.
fred rosenberger wrote:your deck appears to be an array of cards. You create the deck on line 1, as Jeff said - but at that point, there is nothing in it.
There are NUMBER_OF_CARDS null references. That's something. (Okay, I guess semantically it's nothing.)
Joined: Sep 25, 2012
Thanks for the replies everyone!
Sorry, I should have been more specific.
I know that line 1 for sure creates the deck object with quantity NUMBER_OF_CARDS.
On line 5, I moved my cursor on 'Card' and it was referring to my Card class. But, I am not sure why you would need to use 'new' or have to access the Card class.
What exactly is line 5 stating?
As Fred Rosenberger said, it seems that the for loop is creating, or giving values, to each elements in the deck array (0-51). However, how can you have two columns (face and suit) when the deck object is first initialized with NUMBER_OF_CARDS, which is a final value of 52? Wouldn't you have to have two different arrays for faces and suits?