in java i want the code Extra Credit Video Poker Objective: Create a game of vid
ID: 3717617 • Letter: I
Question
in java i want the code
Extra Credit
Video Poker
Objective:
Create a game of video poker with a graphical user interface (GUI). The player should start with $100, and then the system deals out 5 playing cards. After the player sees the cards they are then asked to wager $10, $20, $50, or $100. Next the user picks which cards they wish to throw away, and then the system deals more cards in their place. Once this has concluded money are awarded by these criteria:
Nothing – Player loses their wager
Pair – Player gets back their wager
Two Pair – Player wins wager x 2
3 of a kind – Payer wins wager x 3
Full House – Player wins wager x 6
Flush – Player wins wager x 10
Straight – Player wins wager x 15
4 of a kind – Player wins wager x 20
Royal Flush – Player wins wager x 100
If the player’s cash is less than or equal to 0 the game is over, and they restart with $100. Also once they close the program it should store the score in a file that once they restart it they begin with the score they once had.
Explanation / Answer
As per your requirement i have written java code which fulfill all your requirements and for better understanding i have included comments for each and every code logic please follow it step by step
/**
* PokerHand.java
* Here is class that represents a Poker Hand. And it is mainly
* useful for a draw poker game in which the hand is made up of different types like
* 5 Cards. The rank are as follows: 9 - Royal Flush; 8 - Straight
* Flush; 7 - Four of a Kind; 6 - Full House; 5 - Flush; 4 - Straight;
* 3 - Three of a Kind; 2 - Two Pair; 1 - Pair; 0 - Bust (nothing)
*/
public class PokerHand {
private CardElement [] hand;
private int rankElement;
/**
* PokerHand(CardElement c1, CardElement c2, CardElement c3, CardElement c4, CardElement c5)
* Input: Here will take 5 CardElement objects which will make up the poker hand
* Output: none
* Description: Here we creates a PokerHand object with the 5 CardElements
* passed in as parameters. It uses the evalrankElement() method for functionality
* to give assign a rankElement to the hand.
*/
public PokerHand(CardElement c1, CardElement c2, CardElement c3, CardElement c4, CardElement c5) {
hand = new CardElement[5];
hand[0] = c1;
hand[1] = c2;
hand[2] = c3;
hand[3] = c4;
hand[4] = c5;
evalrankElement();
}//end Constructor
/**
* PokerHand()
* Input: none
* Output: none
* Description: Here we will Creates a random poker hand through a call to the
* other poker hand constructor and the random CardElement constructor.
*/
public PokerHand() {
this(new CardElement(), new CardElement(), new CardElement(), new CardElement(), new CardElement());
}//end Constructor
/**
* getrankElement()
* Input: none
* Output: an integer representing the rankElement of the CardElement
*/
public int getrankElement() {
return rankElement;
}//end getrankElement
/**
* hasAce()
* Input: none
* Ouptut: Expected output is boolean - true if hand has an ace, false otherwise
* Description: Actually here we will use simple utility method used to determine whether
* the hand has an ace or not
*/
public boolean hasAce() {
for(int i = 0; i < 5; i++)
if(hand[i].getrankElement() == 14)
return true;
return false;
}//end hasAce
/**
* gameToString()
* Input: none
* Output: a String representation of the hand
* Description: A method that is useful in the DrawPoker
* game - prints out the hand numbered without printing
* out the rankElement (the user should figure that out!)
*/
public String gameToString() {
String resultElement = new String("");
for(int i = 0; i < hand.length; i++)
resultElement += "(" + (i+1) + ") " + hand[i] + " ";
return resultElement;
}//end gameToString
/**
* rankElementToString(int rankElement)
* Input: an integer representing the rankElement
* Output: a string representation of the corresponding rankElement
* Description: A static method that might be useful for printing
* out the rankElement.
*/
public static String rankElementToString(int rankElement) {
switch(rankElement) {
case 0: return "Bust ";
case 1: return "Pair ";
case 2: return "Two Pair ";
case 3: return "3 of a Kind ";
case 4: return "Straight ";
case 5: return "Flush ";
case 6: return "Full House ";
case 7: return "4 of a Kind ";
case 8: return "Straight Flush";
case 9: return "Royal Flush ";
default: return "Error ";
}
}//end rankElementToString
/**
* draw(int index, CardElement c)
* Input: An integer representing the index of the
* CardElement to be disCardElemented and the CardElement with which
* it should be replaced.
* Output: none
* Description: Replaces the CardElement at the corresponding index
* with a new CardElement.
*/
public void draw(int index, CardElement c) {
if(0 <= index && index <= 4) {
hand[index] = c;
}
evalrankElement();
}//end draw
/**
* hasGoodPair()
* Input: none
* Output: Actually expected output is boolean which is true if the hand
* is a pair of Jacks or better
*/
public boolean hasGoodPair() {
boolean resultElement;
resultElement = false;
if(rankElement == 1) {
for(int i = 0; i < 5; i++) {
for(int j = i+1; j < 5; j++)
if(hand[i].getrankElement() == hand[j].getrankElement() && hand[i].getrankElement() > 10)
resultElement = true;
}
}
return resultElement;
}//end hasGoodPair
/**
* toString()
* Input: none
* Output: String representing the hand
* Description: A method that returns the String representation
* of this CardElement hand - including the rankElement.
*/
public String toString() {
evalrankElement();
String resultElement = "";
switch(rankElement) {
case 0:
resultElement += "Bust";
break;
case 1:
resultElement += "Pair";
break;
case 2:
resultElement += "Two Pair";
break;
case 3:
resultElement += "Three of a Kind";
break;
case 4:
resultElement += "Straight";
break;
case 5:
resultElement += "Flush";
break;
case 6:
resultElement += "Full House";
break;
case 7:
resultElement += "Four of a Kind";
break;
case 8:
resultElement += "Straight Flush";
break;
case 9:
resultElement += "Royal Flush";
break;
default:
resultElement += "Nothing";
break;
}
resultElement += ": " + hand[0] + ", " + hand[1] + ", " + hand[2] + ", " + hand[3] + ", " + hand[4] +" ";
return resultElement;
}//end toString
/**
* evalrankElement()
* Input: none
* Output: none
* Description: A method that computes the rankElement of the hand.
*/
private void evalrankElement() {
CardElement [] sortedHandElement = new CardElement[5];
for(int i = 0; i < 5; i++)
sortedHandElement[i] = hand[i];
this.sort(sortedHandElement);
int pairIndex = -1;
rankElement = 0; //assume its a BUST
//check for pair
for(int i = 0; i < 4; i++)
if(sortedHandElement[i].getrankElement() == sortedHandElement[i+1].getrankElement()) {
pairIndex = i;
rankElement = 1;
i = 4;
}
//check for 2 pair
if(rankElement == 1) {
for(int i = pairIndex + 2; i < 4; i++)
if(sortedHandElement[i].getrankElement() == sortedHandElement[i+1].getrankElement())
rankElement = 2;
}
//check for 3 of a kind or full house
for(int i = 0; i < 3; i++)
if(sortedHandElement[i].getrankElement() == sortedHandElement[i+1].getrankElement() && sortedHandElement[i+1].getrankElement() == sortedHandElement[i+2].getrankElement()) {
rankElement = 3;
if(i==0 && sortedHandElement[3].getrankElement()==sortedHandElement[4].getrankElement() || i==2 && sortedHandElement[0].getrankElement() == sortedHandElement[1].getrankElement())
rankElement = 6;
}
//check for 4 of a kind
for(int i = 0; i < 2; i++)
if(sortedHandElement[i].getrankElement() == sortedHandElement[i+1].getrankElement() && sortedHandElement[i+1].getrankElement() == sortedHandElement[i+2].getrankElement() &&
sortedHandElement[i+2].getrankElement() == sortedHandElement[i+3].getrankElement()) {
rankElement = 7;
}
//check for straight (if we haven't already found any pairs)
if(rankElement == 0)
if((sortedHandElement[4].getrankElement() - sortedHandElement[0].getrankElement() == 4) ||
(sortedHandElement[3].getrankElement() - sortedHandElement[0].getrankElement() == 3 && sortedHandElement[4].getrankElement() == 14 && sortedHandElement[0].getrankElement() == 2)) {
rankElement = 4;
}
//check for flush (if we haven't already found any pairs)
boolean flush;
if(rankElement == 0 || rankElement == 4) {
flush = true;
for(int i = 0; i < 4; i++)
if(sortedHandElement[i].getSuit() != sortedHandElement[i+1].getSuit())
flush = false;
if(flush && rankElement == 4)
rankElement = 8; //straight flush!
else if(flush)
rankElement = 5;
}
//check for royal flush (if it's a straight flush)
if(rankElement == 8 && sortedHandElement[4].getrankElement() == 14 && sortedHandElement[0].getrankElement() == 10)
rankElement = 9; //royal flush!
}//end evalrankElement
/**
* sort(CardElement [] a)
* Input: A CardElement array
* Output: Expected output is none
* Description: Here we will Sorts an array of CardElements using a selection sort
* algorithm. Used by the evalrankElement() method.
*/
private void sort(CardElement [] a) {
CardElement temporary;
int minimumIndex;
for(int i = 0; i < a.length; i++) {
minimumIndex = i;
for(int j = i; j < a.length; j++) {
if(a[minimumIndex].isHigher(a[j]))
minimumIndex = j;
}
//swap the elements at i and j
temporary = a[minimumIndex];
a[minimumIndex] = a[i];
a[i] = temporary;
}
}//end sort
}//end class
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.