public void shuffle(); // Post: The cards currently in the deck are randomly shuffled. public void reInit(); // Post: The deck is refilled in order: 2 of clubs .. ace of spades public void deal(int n); // Pre: There are still n cards in the deck // Post: The "top" n cards are printed and removed from the deck public void showIt(); // Post: All cards in the deck are displayedOf course, there should also be a constructor and any other necessary methods, including a
main()
method which tests your
Deck
class. Also consider implementing a toString()
method. It should be easy to implement once you've thought about the
showIt()
method.
The deck should be implemented as an array of CardInterface
.
The second part of the assignment is to provide a new implementation of
the Card
class, and then use it in your Deck
class.
The new card class, called OtherCard
, should implement a card
as a number between 0 and 51, where 0-12 represents the clubs (2..Ace),
13-25 represent the diamonds, and so on. This will require rewriting of
the bodies of several of the methods in the Card class.
The easiest way to do this part of the assignment is to copy my
Card.java
file and edit it. Using OtherCard
in place of Card
should require only minor modifications to
the Deck
class if you've been using CardInterface for the types
of variable and parameters.
Please note that this assignment is not simply asking you to type the (similar) methods given as examples in the Core Java text. Try doing this assignment without even referring to those.
OtherCard
and Deck
classes.
The Deck
class should include a main method which tests your Deck.
Always try to test your classes thoroughly.
For example, shuffle, deal some hands, re-initialize, shuffle again, etc.,
printing the deck contents after each operation.Back to:
andrea@cs.williams.edu