CS 151 – Programming Assignment 1 – Five Card Draw CS 151 Spring 2020 Programming Assignment 1 – Five Card Draw Dr. William Kreahling February 19, 2020 Overview For this assignment you are writing a...

1 answer below »
Must have javadoc comments


CS 151 – Programming Assignment 1 – Five Card Draw CS 151 Spring 2020 Programming Assignment 1 – Five Card Draw Dr. William Kreahling February 19, 2020 Overview For this assignment you are writing a program that plays a hand of five card draw between one computer player and the computer. Your program should use the following rules: • When the hands are first dealt you see your cards, but not the computers. After the discard, you should see both hands. • After the discards, display both hands, print out who won the game, what hand they had and exit. • It is imperative to note I have loosened up the rules to make the game easier to code. Make note of the places where my rules are different that the traditional rules of five card draw. In several cases you may follow the traditional rules for bonus points. These cases are clearly stated. Information You will need the following enumerations: 1. Suit - model the suit of a card. Must work with the supplied Card class. 2. Face - models the face value of a card. Should contain the name of the card, the points, and the rank of the card. We will rank the cards from 1 to 13 (Ace to King). The values of the cards are their numerical face value with ace being 1, and king, queen, and jack all being worth 10. 3. WinHand - models the winning hands of poker as well as an invalid state. • Straight flush • Four of a kind • Full house • Flush • Straight • Three of a kind • Two pair • Pair • HighCard (in the absence of all other hands, highcard wins) You will need the following Classes: You need to have a good reason why classes are public, private, protected, or package access. 1. Card - models a playing card. (This class is supplied). 2. Hand - models a hand of five card draw. • Fields needed to represent a single hand of cards. You must use an array. All fields must be private. 1 CS 151 Spring 2020 • Constructor that accepts the number of cards in a hand and creates a hand capable of holding that many Cards. • A default constructor that creates a hand capable of holding 5 cards. This constructor must call the other constructor to accomplish its goal. • setCard - sets a card in the hand (replaces a single Card in the hand with another). • getPair - returns an int representing the rank of the cards comprising the pair in this hand. • getThreeKind - returns an int representing the rank of the cards comprising the three of a kind in this hand. • getFourKind - returns an int representing the rank of the cards comprising the four of a kind in this hand. • getHighestCard - returns the highest Card in this hand. (public method) • getHandType returns a reference to a WinHand enumeration representing the type of hand this is. (public method) • straightFlush - helper method that returns true if the hand contains a straight flush. • straight - helper method that returns true if the hand contains a straight. • fourOfAKind - helper method that returns true if the hand contains a four of a kind. • threeOfAKind - helper method that returns true if the hand contains a three of a kind. • pair - helper method that returns true if the hand contains a pair. • twoPair - helper method that returns true if the hand contains two pairs. • fullHouse - helper method that returns true if the hand contains a full house. • flush - helper method that returns true if the hand contains a flush. • toString - returns a string indicating each cards as well as a number the user can press to indicate they wish to discard this card. see sample run for an example. • sort - sorts the cards in order. This will make your life easier!. Use the following code: Note this only works in Java 8: Arrays.sort(cards, (Card u1, Card u2) -> u1.compareTo(u2)); You will also need to import java.util.Arrays; 3. Game - models one play of five card draw. You should determine which methods need to be public and which private! You may add other fields and methods, if needed. • Fields: a deck of Cards, a player and a computer Hand. Constants needed to avoid magic numbers, and other fields you deem necessary! • Default constructor - initialized all the fields. • shuffle - the Fisher-Yates Shuffle. • displayDeck - prints out a deck of cards in a nicely formatted fashion. • deal - method that deals two hands of cards. • dealOne - deals one cards to a specific location in a hand. Any card that was in the location before this new card is dealt is no longer in the hand. • go - the main game logic goes here! • printWinner - prints our who won the game and what hand they had • main - should create a Game object and call the go method. 2 CS 151 Spring 2020 • There is no betting for this game. • To simplify things, the computer never asks to discard. If you want to add computer logic, for up to 5 bonus points use the following rules: – Computer keeps a straight, flush, full house, and four of a kind. – nothing – keeps only King, queen, and jack. – pair,two pair – replace all non-pair cards – 3 of a kind – replace non pair cards. – You can make the computer smarter if you know who to play five card draw better than the above stated rules. • If the event of a tie, the player with the highest card in the entire hand wins. For up to five bonus points, the tie breaker is the highest card in the pair, three of a kind/ four, of a kind, flush, etc. In the case of both players having a pair of two’s the suits are used to break the tie. Sample run: > java Game Player : 0 : Ace o f Clubs 1 : Three o f Diamonds 2 : Jack o f Hearts 3 : Queen o f Diamonds 4 : King o f Hearts How many cards to you want to d i s ca rd >2 Which 2 would you l i k e to swap >0 1 Computer : 0 : Three o f Clubs 1 : Five o f Clubs 2 : Nine o f Clubs 3 : Ten o f Spades 4 : Queen o f Spades Player : 0 : Ace o f Spades 1 : Nine o f Spades 2 : Jack o f Hearts 3 : Queen o f Diamonds 4 : King o f Hearts Player wins with a High card > java Game Player : 0 : Four o f Clubs 3 CS 151 Spring 2020 1 : Five o f Diamonds 2 : Five o f Clubs 3 : Eight o f Clubs 4 : Jack o f Diamonds How many cards to you want to d i s ca rd >3 Which 3 would you l i k e to swap >0 3 4 Computer : 0 : Ace o f Diamonds 1 : Deuce o f Clubs 2 : Six o f Clubs 3 : Seven o f Diamonds 4 : King o f Spades Player : 0 : Ace o f Hearts 1 : Five o f Diamonds 2 : Five o f Clubs 3 : Six o f Diamonds 4 : Eight o f Diamonds Player wins with a Pair > java Game Player : 0 : Deuce o f Hearts 1 : Four o f Diamonds 2 : Eight o f Clubs 3 : Nine o f Spades 4 : Jack o f Spades How many cards to you want to d i s ca rd >2 Which 2 would you l i k e to swap >0 1 Computer : 0 : Four o f Clubs 1 : Five o f Diamonds 2 : Five o f Clubs 3 : Seven o f Hearts 4 : Nine o f Clubs Player : 0 : Four o f Hearts 1 : Four o f Spades 2 : Eight o f Clubs 3 : Nine o f Spades 4 : Jack o f Spades Computer wins with a Pair 4 CS 151 Spring 2020 > java Game Player : 0 : Ace o f Clubs 1 : Four o f Spades 2 : Six o f Diamonds 3 : Eight o f Spades 4 : Jack o f Hearts How many cards to you want to d i s ca rd >4 Which 4 would you l i k e to swap >0 1 2 3 Computer : 0 : Five o f Hearts 1 : Seven o f Hearts 2 : Nine o f Hearts 3 : Jack o f Spades 4 : King o f Hearts Player : 0 : Three o f Diamonds 1 : Three o f Hearts 2 : Ten o f Clubs 3 : Ten o f Hearts 4 : Jack o f Hearts Player wins with a Two pa i r > java Game Player : 0 : Four o f Diamonds 1 : Nine o f Spades 2 : Ten o f Clubs 3 : Jack o f Spades 4 : Queen o f Spades How many cards to you want to d i s ca rd >1 Which 1 would you l i k e to swap >0 Computer : 0 : Deuce o f Spades 1 : Three o f Diamonds 2 : Three o f Clubs 3 : Seven o f Spades 4 : Queen o f Clubs Player : 0 : Nine o f Spades 1 : Ten o f Clubs 2 : Jack o f Spades 3 : Queen o f Spades 5 CS 151 Spring 2020 4 : King o f Diamonds Player wins with a Flush Submit: Due Monday February 24th at 11:59 PM Use handin to submit. The command for handing is: handin.151.2 Thus for this assignment it would be: handin.151.2 1 *.java *.txt or even better: tar -cvjf prog1.tbz progam1 handin.151.2 1 prog1.tbz Where program1 is the name of the directory where your files are stored. 6
Answered Same DayFeb 22, 2021

Answer To: CS 151 – Programming Assignment 1 – Five Card Draw CS 151 Spring 2020 Programming Assignment 1 –...

Abhishek answered on Feb 24 2021
150 Votes
51085 - Poker/Screenshots/O11.png
51085 - Poker/Screenshots/O8.png
51085 - Poker/Screenshots/O10.png
51085 - Poker/Screenshots/O7.png
51085 - Poker/Screenshots/O9.png
51085 - Poker/Screenshots/O5.png
51085 - Poker/Screenshots/O1.png
51085 - Poker/Screenshots/O2.png
51085 - Poker/Screenshots/O4.png
51085 - Poker/Screenshots/O6.png
51085 - Poker/Screenshots/O3.png
51085 - Poker/Screenshots/O12.png
51085 - Poker/Problem/poker-3yimk3v1.pdf
CS 151 Spring 2020
Programming Assignment 1 – Five Card Draw
Dr. William Kreahling
February 19, 2020
Overview
For this assignment you are writing a program that plays a hand of five card draw between one computer
player and the computer. Your program should use the following rules:
• When the hands are first dealt you see your cards, but not the computers. After the discard, you
should see both hands.

• After the discards, display both hands, print out who won the game, what hand they had and exit.
• It is imperative to note I have loosened up the rules to make the game easier to code.
Make note of the places where my rules are different that the traditional rules of five
card draw. In several cases you may follow the traditional rules for bonus points. These cases are
clearly stated.
Information
You will need the following enumerations:
1. Suit - model the suit of a card. Must work with the supplied Card class.
2. Face - models the face value of a card. Should contain the name of the card, the points, and the rank
of the card. We will rank the cards from 1 to 13 (Ace to King). The values of the cards are their
numerical face value with ace being 1, and king, queen, and jack all being worth 10.
3. WinHand - models the winning hands of poker as well as an invalid state.
• Straight flush
• Four of a kind
• Full house
• Flush
• Straight
• Three of a kind
• Two pair
• Pair
• HighCard (in the absence of all other hands, highcard wins)
You will need the following Classes: You need to have a good reason why classes are public, private, protected,
or package access.
1. Card - models a playing card. (This class is supplied).
2. Hand - models a hand of five card draw.
• Fields needed to represent a single hand of cards. You must use an array. All fields must be
private.
1
CS 151 Spring 2020
• Constructor that accepts the number of cards in a hand and creates a hand capable of holding
that many Cards.
• A default constructor that creates a hand capable of holding 5 cards. This constructor must call
the other constructor to accomplish its goal.
• setCard - sets a card in the hand (replaces a single Card in the hand with another).
• getPair - returns an int representing the rank of the cards comprising the pair in this hand.
• getThreeKind - returns an int representing the rank of the cards comprising the three of a kind
in this hand.
• getFourKind - returns an int representing the rank of the cards comprising the four of a kind in
this hand.
• getHighestCard - returns the highest Card in this hand. (public method)
• getHandType returns a reference to a WinHand enumeration representing the type of hand this
is. (public method)
• straightFlush - helper method that returns true if the hand contains a straight flush.
• straight - helper method that returns true if the hand contains a straight.
• fourOfAKind - helper method that returns true if the hand contains a four of a kind.
• threeOfAKind - helper method that returns true if the hand contains a three of a kind.
• pair - helper method that returns true if the hand contains a pair.
• twoPair - helper method that returns true if the hand contains two pairs.
• fullHouse - helper method that returns true if the hand contains a full house.
• flush - helper method that returns true if the hand contains a flush.
• toString - returns a string indicating each cards as well as a number the user can press to indicate
they wish to discard this card. see sample run for an example.
• sort - sorts the cards in order. This will make your life easier!. Use the following code: Note this
only works in Java 8:
Arrays.sort(cards, (Card u1, Card u2) -> u1.compareTo(u2));
You will also need to import java.util.Arrays;
3. Game - models one play of five card draw. You should determine which methods need to be public
and which private! You may add other fields and methods, if needed.
• Fields: a deck of Cards, a player and a computer Hand. Constants needed to avoid magic numbers,
and other fields you deem necessary!
• Default constructor - initialized all the fields.
• shuffle - the Fisher-Yates Shuffle.
• displayDeck - prints out a deck of cards in a nicely formatted fashion.
• deal - method that deals two hands of cards.
• dealOne - deals one cards to a specific location in a hand. Any card that was in the location
before this new card is dealt is no longer in the hand.
• go - the main game logic goes here!
• printWinner - prints our who won the game and what hand they had
• main - should create a Game object and call the go method.
2
CS 151 Spring 2020
• There is no betting for this game.
• To simplify things, the computer never asks to discard. If you want to add computer logic, for up
to 5 bonus points use the following rules:
– Computer keeps a straight, flush, full house, and four of a kind.
– nothing – keeps only King, queen, and jack.
– pair,two pair – replace all non-pair cards
– 3 of a kind – replace non pair cards.
– You can make the computer smarter if you know who to play five card draw better than the
above stated rules.
• If the event of a tie, the player with the highest card in the entire hand wins. For up to five bonus
points, the tie breaker is the highest card in the pair, three of a kind/ four, of a kind, flush, etc.
In the case of both players having a pair of two’s the suits are used to break the tie.
Sample run:
> java Game
Player :
0 : Ace o f Clubs
1 : Three o f Diamonds
2 : Jack o f Hearts
3 : Queen o f Diamonds
4 : King o f Hearts
How many cards to you want to d i s ca rd >2
Which 2 would you l i k e to swap >0 1
Computer :
0 : Three o f Clubs
1 : Five o f Clubs
2 : Nine o f Clubs
3 : Ten o f Spades
4 : Queen o f Spades
Player :
0 : Ace o f Spades
1 : Nine o f Spades
2 : Jack o f Hearts
3 : Queen o f Diamonds
4 : King o f Hearts
Player wins with a High card
> java Game
Player :
0 : Four o f Clubs
3
CS 151 Spring 2020
1 : Five o f Diamonds
2 : Five o f Clubs
3 : Eight o f Clubs
4 : Jack o f Diamonds
How many cards to you want to d i s ca rd >3
Which 3 would you l i k e to swap >0 3 4
Computer :
0 : Ace o f Diamonds
1 : Deuce o f Clubs
2 : Six o f Clubs
3 : Seven o f Diamonds
4 : King o f Spades
Player :
0 : Ace o f Hearts
1 : Five o f Diamonds
2 : Five o f Clubs
3 : Six o f Diamonds
4 : Eight o f Diamonds
Player wins with a Pair
> java Game
Player :
0 : Deuce o f Hearts
1 : Four o f Diamonds
2 : Eight o f Clubs
3 : Nine o f Spades
4 : Jack o f Spades
How many cards to you want to d i s ca rd >2
Which 2 would you l i k e to swap >0 1
Computer :
0 : Four o f Clubs
1 : Five o f Diamonds
2 : Five o f Clubs
3 : Seven o f Hearts
4 : Nine o f Clubs
Player :
0 : Four o f Hearts
1 : Four o f Spades
2 : Eight o f Clubs
3 : Nine o f Spades
4 : Jack o f Spades
Computer wins with a Pair
4
CS 151 Spring 2020
> java Game
Player :
0 : Ace o f Clubs
1 : Four o f Spades
2 : Six o f Diamonds
3 : Eight o f Spades
4 : Jack o f Hearts
How many cards to you want to d i s ca rd >4
Which 4 would you l i k e to swap >0 1 2 3
Computer :
0 : Five o f Hearts
1 : Seven o f Hearts
2 : Nine o f Hearts
3 : Jack o f Spades
4 : King o f Hearts
Player :
0 : Three o f Diamonds
1 : Three o f Hearts
2 : Ten o f Clubs
3 : Ten o f Hearts
4 : Jack o f Hearts
Player wins with a Two pa i r
> java Game
Player :
0 : Four o f Diamonds
1 : Nine o f Spades
2 : Ten o f Clubs
3 : Jack o f Spades
4 : Queen o f Spades
How many cards to you want to d i s ca rd >1
Which 1 would you l i k e to swap >0
Computer :
0 : Deuce o f Spades
1 : Three o f Diamonds
2 : Three o f Clubs
3 : Seven o f Spades
4 : Queen o f Clubs
Player :
0 : Nine o f Spades
1 : Ten o f Clubs
2 : Jack o f Spades
3 : Queen o f Spades
5
CS 151 Spring 2020
4 : King o f Diamonds
Player wins with a Flush
Submit:
Due Monday February 24th at 11:59 PM
Use handin to submit. The command for handing is:
handin.151.2
Thus for this assignment it would be:
handin.151.2 1 *.java *.txt
or even better:
tar -cvjf prog1.tbz progam1
handin.151.2 1 prog1.tbz
Where program1 is the name of the directory where your files are stored.
6
51085 - Poker/Problem/card-z45g2stb.java
51085 -...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here