I'm a beginner, trying to solve exercises in the book- Java How To Program by Paul Deitel and Harvey Deitel.
I'm stuck on exercise 7.34. Can anybody with the book help me out here ?
To be specific, how can I use enumeration of one source-code file in another. Thanks in advance.
I do have the source files but everyone of them contains some Copyright blabber(mentioned in comments).
Nevertheless, let me rephrase the question and come to the point:
Suppose there is class Card containing an enum type and a constructor which takes this enum type as parameter like the one below:
Now there is another class Deck which needs the objects of class Card. My question: How to declare object of class Card in the class Deck?
Hope I have have made clear this time.
P.S.-I have bought the book.
Hartej Grewal wrote:Suppose there is class Card containing an enum type
[and] another class Deck which needs the objects of class Card. My question: How to declare object of class Card in the class Deck?
Why would you need to? A Deck is likely to be a set of Cardds (note that it's in lower case, because I don't necessarily mean a java.util.Set), so it doesn't define them; it uses (or 'has') them (probably via an internal array or List ).
If that doesn't explain your confusion, then perhaps you need to explain your problem in a bit more detail.
Hartej Grewal wrote:Anyways I figured it out. This might help someone. The key was- nested enums are implicitly static.
Example: new Card(Card.Suit.HEARTS)
Well done. And thanks for posting your solution.
However, I don't agree with the design, which suggests that ALL cards are necessarily divided into Suits. Maybe for another day though.