Labs
Rank and Suit are available in the solutions.cards package. Use them to create the classes in these labs. Be sure to copy-paste them into the package where you create your new classes.
- Create a class called
Card. - A card has a
SuitandRank. Set these in the constructor. - Generate the methods
hashCodeandequals - Add a
toStringwhich saysrank + " of " + suit. - Add a method
getValueto return the card's numeric value.
(Solution: Card.java)
- We will be simulating a deck of cards.
- Create a class
Deck. It will hold aListofCards. - In the constructor, initialize the
Listwith all 52 cards. - Add a method
checkDeckSizewhich returns the number of cards still in the deck. - Add a method
dealCardthat removes aCardfrom the deck. - Add a method
shuffleto shuffle the deck.
(Solution: Deck.java)
- Write a program to ask a user how many cards they want.
- Handle the case where users enter a non-integer or a number greater than
52: print an error message.
Deal the cards and display them on the screen. Also display the total value of all cards.
(Solution: Dealing.java)