is there an API in ArrayList class that moves(adds to receiver and remove from giver) element across ArrayLists?
luck, db
There are no new questions, but there may be new answers.
Dave Tolls wrote:For your card arrays they should be encapsulated.
That way you can simply do in the Game code:
and leave the implementation of those two methods (addCard and drawCard) to the relevant classes.
At the moment the Game class has to handle the addition of the card as well as its removal from the array in the Deck class.
And a minor point, but that should be Card, not Cards. An instance of that class represents a single card, not several cards.
Darryl Burke wrote:A couple of comments:
-- Suit and rank attributes in a deck of cards are better represented by enums rather than a String and an int.
-- Your class that represents a card (singular) is called Cards (plural). That's misleading. Why not name it Card?
All that matters to the user of the Deck class is that it can supply a Card. How it does that and how the remaining cards are stored is an internal matter of the Deck. So yes, its ArrayList should be private, and Deck could have a public or package-private method Card getCard().
Similar logic would apply to the Player class.
is there an API in ArrayList class that moves(adds to receiver and remove from giver) element across ArrayLists?
Hint: what does the remove(int) method return?
Raed Tabani wrote:
Dave Tolls wrote:For your card arrays they should be encapsulated.
but why they "should" be encapsulated?
Darryl Burke wrote:All that matters to the user of the Deck class is that it can supply a Card. How it does that and how the remaining cards are stored is an internal matter of the Deck.
luck, db
There are no new questions, but there may be new answers.
Raed Tabani wrote:about the enums, being unfamiliar with them, I want to ask why are they better to represent my cards suits and numbers? from my brief and very recent knowledge of the enum Class I sort of built this picture of it as a global Array with constant values, that is accessable across classes. so in a way is it to overcome the restriction imposed by encapsulation and private modifiers since multiple classes need to use them?
luck, db
There are no new questions, but there may be new answers.
Raed Tabani wrote:
hi Dave,
but why they "should" be encapsulated? to me it seems as if to say each class mind your own variables. but I guess on the positive side, it does forces you to implement methods to their relevant classes, as you said.
so right now, I'll be implementing DrawCard() in Deck Class and addCard() in Player class
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |