Saikrishnan Srivatsan wrote:Thanks Stephan. Do you question my Deck class because card isn't really an "attribute" of deck?
Saikrishnan Srivatsan wrote:Thanks Winston. Yes, I intended for the deck to mean a deck of cards specifically when I wrote it. Now I am slightly confused if card is really an "attribute" of the deck class. A deck doesn't exist before a card is created unlike an address book which still exists even before any entries are stored in it. In cases like these, can it still be an attribute?
Saikrishnan Srivatsan wrote:Thanks Stephan. Do you question my Deck class because card isn't really an "attribute" of deck? Is that why I should have just a helper class to generate a deck of cards and also provide methods like shuffle in that class?
Sorry, I don't understand what I've missed Winston Also, card being an attribute of the Deck class is wrong?
Winston Gutkowski wrote:But maybe you've missed out another important relationship: it is also specified by the Game.Winston
Saikrishnan Srivatsan wrote:Sorry, I don't understand what I've missed Winston Also, card being an attribute of the Deck class is wrong?
Winston Gutkowski wrote:(actually, more likely, a Set (see java.util.Set))
Stephan van Hulst wrote:Disagree! There are good reasons to make Cards with the same suit and rank equal. This does not mean that a particular game may only have one of each. Think Canasta
If the original poster had used the name "Pack" instead of "Deck", is it still wrong to have a Card attribute inside the Pack class?
Winston Gutkowski wrote:Perhaps the problem is that what you call a "deck", I'd call a "pack".
Agreed, thanks. I've got rid of the values.
Stephan van Hulst wrote:First of all, I wouldn't give Ranks a value. Card values are properties of specific card games, not of the cards themselves.
I've removed the toString() methods and changed the unicode characters to strings.
Stephan van Hulst wrote:For your Suit enum, why are you not embedding the symbols in Strings directly? "\u2660" versus '\u2660'. I would also not return these characters in the toString() method, because toString() is often used for debugging purposes, and not all viewers display such symbols correctly.
When I'm designing a just the pack of cards and not an actual game, I thought I'd create all the cards in my program and give it to the user. So, I didn't think of a user creating a card.
Stephan van Hulst wrote:You're not doing any parameter checking on your Card class. What if a user constructs a card with null values?
OK, thank you for pointing this out. My intention first was just to design a pack of cards correctly, and not a game. So I just used that class to hold my cards. I'll get rid of that when I start doing the game.
Stephan van Hulst wrote:I don't mean this in a rude way, but your Pack class is pretty useless. Right now it's just a wrapper around a list, which does nothing else than provide a layer of indirection.
We should throw him a surprise party. It will cheer him up. We can use this tiny ad:
Create Edit Print & Convert PDF Using Free API with Javahttps://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire