• Post Reply Bookmark Topic Watch Topic
  • New Topic

Stuck on an Exercise  RSS feed

 
Hartej Grewal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello folks,

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.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hartej Grewal wrote:I'm stuck on exercise 7.34. Can anybody with the book help me out here ?

Not unless anyone has read the book (and has it to hand) or you describe the problem yourself.

Winston
 
Hartej Grewal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for that. But the reason I didn't post the entire problem was that it requires some code from source files or examples associated with the book.

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.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Winston
 
Hartej Grewal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks but that doesn't help a lot.

Anyways I figured it out. This might help someone. The key was- nested enums are implicitly static.

Example: new Card(Card.Suit.HEARTS)
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!