UsernameA15
)
Finish A15 by writing a dealer class (named UsernameA15
) that allows a human user to ask for cards from a Deck
.
The idea of this program is that, when you go to a casino, you don't usually get to touch the deck yourself. Instead, you ask the dealer for a certain number of cards. If the dealer runs out of cards, he opens a new deck and the game continues.
Write a program that allows the user to draw as many cards as she'd like from a shuffled deck. Each card drawn should be displayed one per line. If she asks for 0 cards, your program should quit. (It's up to you whether you want to treat negative numbers as an error or an indication to quit.)
After each draw, your program should state how many cards remain in the deck.
If the last card in the deck is drawn, a new shuffled deck should be created so that drawing may continue until the total number of requested cards have been drawn. The program should indicate when a new deck has been "opened"/created.
This is your digital deck of playing cards! A new deck has already been opened and shuffled for you. [52 cards left in deck] How many cards to draw (0 to quit)? one Error: Please enter a number >= 0. [52 cards left in deck] How many cards to draw (0 to quit)? 1 5 of Hearts [51 cards left in deck] How many cards to draw (0 to quit)? 3 Ace of Diamonds 7 of Diamonds 9 of Clubs [48 cards left in deck] How many cards to draw (0 to quit)? 7 8 of Hearts 8 of Diamonds 8 of Spades 5 of Diamonds 4 of Diamonds Jack of Hearts 2 of Diamonds [41 cards left in deck] How many cards to draw (0 to quit)? 45 King of Diamonds 3 of Diamonds King of Clubs 3 of Clubs Jack of Clubs 6 of Spades Queen of Hearts 6 of Diamonds Queen of Diamonds 4 of Spades 9 of Diamonds 10 of Diamonds Jack of Diamonds Ace of Clubs Ace of Hearts 10 of Spades 2 of Hearts 3 of Hearts Ace of Spades 4 of Hearts 6 of Hearts 7 of Hearts 9 of Hearts 10 of Hearts 3 of Spades King of Hearts 2 of Spades Queen of Spades 5 of Clubs 5 of Spades 7 of Spades 9 of Spades 7 of Clubs Jack of Spades King of Spades 2 of Clubs 4 of Clubs 6 of Clubs 8 of Clubs 10 of Clubs Queen of Clubs [--Opened a new deck--] Ace of Clubs 8 of Clubs 8 of Diamonds Ace of Diamonds [48 cards left in deck] How many cards to draw (0 to quit)? 0
Paste your other two classes into your UsernameA15.java
file. Remember that you will need to remove the public
modifier when from those two classes when you do this. Also, remember to be careful not to accidentally put one class within another. Your file should then be structured like this:
public class UsernameA15 { //... your main method in here ... } class Deck { //... contents of the Deck class ... } class PlayingCard { //... contents of PlayingCard class ... }
You may want to try deleting your .class files and compiling and running your UsernameA15.java one last time before you submit.
Then, upload your complete UsernameA15.java
file to Tamarin.
PlayingCard
get
methods (0.5), and toString()
(1.0) are named correctly and work as specified in the provide /** javadocs */.
Deck
draw()
(0.5), getSize()
(0.5) and shuffle()
(1.0) methods. All perform correctly as specified in the provided /** javadocs */.
UsernameA15