> I would take a somewhat different approach for this.
<hdquimby@yahoo.com> wrote...
>> I would take a somewhat different approach for this.
>
> Unfortunately, this is for a class and I must follow the given
> protocol, although I don't need to create a class like the Die class,
> but something like it. I am in an Intro class. Thanks though.
Well, you didn't spell out what "protocol" you're given, so my approach
could very well work for the stated assignment: To "create" random cards,
each with a suit and face value...
I think it would be unfortunate of your teacher to not accept a solution
that is more OO, as OO design always tries to "mimic" the real world objects
as the first option (which in my world is 52 cards in a deck, from which
cards are drawn). Unlike dices a Card has a fixed value...
Very well, if the teacher insist on cards acting like dices, you can simply
use the same pattern, but create random face and suit values instead of just
a face value.
You will stumble upon another problem though; to check that the randomized
Card isn't already "created", in which case you have to "redo" the card
again, as I believe that there will *still* be only one Ace of Spades...
// Bjorn A
Frank - 10 Mar 2005 10:42 GMT
> <hdquimby@yahoo.com> wrote...
>
[quoted text clipped - 12 lines]
> as the first option (which in my world is 52 cards in a deck, from which
> cards are drawn). Unlike dices a Card has a fixed value...
I'm thinking he wanted a 'more OO' approach.
Perhaps if you throw in a full-fledged Deck-class there, with methods
like shuffle, draw and cardsRemaining, encapsulating that Cards-array
you already mentioned.