Due: At midnight, November 2, 2001, submit is turned off automatically. Work turned in after that time will not be accepted for grading.
For this assignment you are to create computer game called "In Between". This is a card game played with a standard 52 card deck. The basic idea is that the player is dealt two cards. If the next card drawn falls between the two cards dealt to the player, then the player wins, otherwise the player loses. The player controls the game by deciding how much to bet after seeing their two cards, but before seeing the third card (obviously).
Here are the exact rules.
Here are the additional requirements:
For this assignment you will need to use some non-standard types that represent cards and a deck. You can find the documentation for these classes here. These classes are installed on the lab machines in the same location as tio so you don't need to do anything extra to use them in the lab. If you want to use them at home, copy cards.jar into the same location you copied tio.jar. Be sure and right click on the link and use "Save As". Just left clicking the link will not work.
You will need to add import cards.*; at the top of your
source file. To create a deck of cards use:
Deck theDeck = new Deck(seed);
The seed is some user specified integer to "seed" the random number
generator. Using a seed allows us to play the exact same sequence of
cards over and over for testing.
To shuffle the deck use:
theDeck.shuffle();
To draw a card use:
Card someCard = theDeck.draw();
To find out the value of a card use:
int value = someCard.getValue(); // a value in the range 1 to 13
You can try out my version of the program on the lab machines by
typing:
java SampleInBetween
Here are some sample executions. To save you some typing, you will
want to use file redirection during the final stages of testing.
The input for the two examples below can be found in
hw6Input1 and
hw6Input2. Save these to a file and then
you can test with something like "java myProgram < hw6Input1".
os-prompt>java SampleInBetween Enter a random number to start the game. 22 Let's play In-Between. After seeing your cards you can bet up to $10 that the next card will be between the two cards in your hand. If the next card drawn is between the 2 cards in your hand you win the amount bet. If the next card matches one of your cards it is a draw and the next hand is free. If your hand is a pair, or the cards are adjacent (e.g. 4 and5), then you automatically lose $1 (no third card is drawn). Otherwise you lose the amount bet. Shuffling the deck... You have: 7:diamonds , 9:clubs You have $100. How much do you want to bet? $1 to $10 1 The next card is Jack:clubs You lose. You have $99 Do you want to continue playing (y/n)? y You have: 3:spades , 2:diamonds You lose $1. You have $98 Do you want to continue playing (y/n)? y You have: 10:diamonds , 9:spades You lose $1. You have $97 Do you want to continue playing (y/n)? y You have: 4:hearts , 7:hearts You have $97. How much do you want to bet? $1 to $10 1 The next card is 10:clubs You lose. You have $96 Do you want to continue playing (y/n)? y You have: 3:hearts , Ace:diamonds You have $96. How much do you want to bet? $1 to $10 1 The next card is King:diamonds You lose. You have $95 Do you want to continue playing (y/n)? y You have: 9:hearts , 4:spades You have $95. How much do you want to bet? $1 to $10 1 The next card is 10:spades You lose. You have $94 Do you want to continue playing (y/n)? y You have: Ace:clubs , 2:clubs You lose $1. You have $93 Do you want to continue playing (y/n)? y You have: 4:clubs , Queen:spades You have $93. How much do you want to bet? $1 to $10 10 The next card is 8:clubs You win. You have $103 Do you want to continue playing (y/n)? y You have: 9:diamonds , King:clubs You have $103. How much do you want to bet? $1 to $10 1 The next card is Queen:clubs You win. You have $104 Do you want to continue playing (y/n)? n Thanks for playing. You ended up with $104. os-prompt>java SampleInBetween Enter a random number to start the game. 1234 Let's play In-Between. After seeing your cards you can bet up to $10 that the next card will be between the two cards in your hand. If the next card drawn is between the 2 cards in your hand you win the amount bet. If the next card matches one of your cards it is a draw and the next hand is free. If your hand is a pair, or the cards are adjacent (e.g. 4 and5), then you automatically lose $1 (no third card is drawn). Otherwise you lose the amount bet. Shuffling the deck... You have: 6:diamonds , Jack:spades You have $100. How much do you want to bet? $1 to $10 10 The next card is Queen:hearts You lose. You have $90 Do you want to continue playing (y/n)? y You have: Queen:diamonds , Ace:hearts You have $90. How much do you want to bet? $1 to $10 10 The next card is Ace:clubs That's a draw. You have $90 Do you want to continue playing (y/n)? x Please enter yes or no. yes You have: 10:clubs , 10:diamonds You lose $1. You have $89 Do you want to continue playing (y/n)? y You have: 8:spades , 2:diamonds You have $89. How much do you want to bet? $1 to $10 20 Sorry, that is not a legal bet. How much do you want to bet? $1 to $10 10 The next card is Jack:diamonds You lose. You have $79 Do you want to continue playing (y/n)? y You have: Queen:spades , 9:spades You have $79. How much do you want to bet? $1 to $10 10 The next card is 3:diamonds You lose. You have $69 Do you want to continue playing (y/n)? y You have: King:diamonds , 5:spades You have $69. How much do you want to bet? $1 to $10 10 The next card is King:hearts That's a draw. You have $69 Do you want to continue playing (y/n)? n Thanks for playing. You ended up with $69.