Hello, this is a beginner Java programming assignment. Please use Arrays and loo
ID: 3664115 • Letter: H
Question
Hello, this is a beginner Java programming assignment. Please use Arrays and loops and some fundation methods. Also please create new methods for each hands. And please add some comment. Thank you.
By the end of this assignment you will have created a program that can compare two poker hands and declare a winner. If you've never played poker, review wikipedia for the list of winning hands (in order) . straight flush . four of a kind . full house . flush straight three of a kind two pair . one pair . high card We will be storing both the card values and suits in arrays. Values will range from: Number Representation Card Value A(Ace) 10 10 12 13 ac Q (Queern K (King And suits will be stored with chars Suit Char Representation Valu Diamonds Hearts ClubsExplanation / Answer
dear student
please work on this programme
//external variables
014
int straight, flush, four, three;
015
int pairs = 0;
016
017
void dealACard(int suitsInHand[], int facesInHand[],char *suits[], char *faces[], int deck[][FACES]);
018
void dealAHand(int suitsInHand[], int facesInHand[], char *suits[], char *faces[], int deck[][FACES]);
019
void analyzeHand(int suitsInHand[], int facesInHand[]);
020
void printResults(int suitsInHand[], int facesInHand[], int *pointValue);
021
022
main(){
023
char *suits[4] = { "Hearts", "Diamonds", "Spades", "Clubs" };
024
char *faces[13] = { "Two", "Three", "Four", "Five", "Six", "Seven",
025
"Eight", "Nine", "Ten", "Jack", "Queen", "King", "Ace" };
026
int deck[4][13] = { { AVAILABLE } };
027
028
int suitsInHand[4] = {0} ;
029
int facesInHand[13] = {0};
030
031
int suitsInHand2[4] = {0};
032
int facesInHand2[13] = {0};
033
034
int player1Points = 0;
035
int player2Points = 0;
036
srand( time( NULL ) );
037
038
printf("Player 1 was dealt: ");
039
dealAHand(suitsInHand, facesInHand, suits, faces, deck);
040
analyzeHand(suitsInHand, facesInHand);
041
printResults(suitsInHand, facesInHand, &player1Points);
042
043
044
printf("Player 2 was dealt: ");
045
dealAHand(suitsInHand2, facesInHand2, suits, faces, deck);
046
analyzeHand(suitsInHand2, facesInHand2);
047
printResults(suitsInHand2, facesInHand2, &player2Points);
048
049
if(player1Points > player2Points) {
050
printf( "Congrats, you won this hand " );
051
}
052
else if(player1Points < player2Points) {
053
printf( "Ahh, too bad. This Round goes to me " );
054
}
055
else
056
printf( "A Tie " );
057
058
system("pause");
059
060
}
061
void dealAHand(int suitsInHand[], int facesInHand[], char *suits[], char *faces[], int deck[][FACES]){
062
int i;
063
for(i = 0; i < 5; i++)
064
dealACard(suitsInHand, facesInHand, suits, faces, deck);
065
066
printf(" ");
067
}
068
void dealACard(int suitsInHand[], int facesInHand[], char *suits[], char *faces[], int deck[][FACES]){
069
int suitIndex, faceIndex;
070
071
suitIndex = rand() % 4;
072
faceIndex = rand() %13;
073
074
075
while( deck[suitIndex][faceIndex] == TAKEN ){
076
suitIndex = rand() % 4;
077
faceIndex = rand() %13;
078
}
079
deck[suitIndex][faceIndex] = TAKEN;
080
081
facesInHand[faceIndex]++;
082
suitsInHand[suitIndex]++;
083
084
printf("%s of %s ", faces[faceIndex], suits[suitIndex]);
085
}
086
087
void analyzeHand(int suitsInHand[], int facesInHand[])
088
{
089
int num_consec = 0;
090
int rank, suit;
091
092
straight = FALSE;
093
flush = FALSE;
094
four = FALSE;
095
three = FALSE;
096
pairs = 0;
097
098
for (suit = 0; suit < SUITS; suit++)
099
if (suitsInHand[suit] == 5)
100
flush = TRUE;
101
102
rank = 0;
103
while (facesInHand[rank] == 0)
104
rank++;
105
106
for (; rank < FACES && facesInHand[rank]; rank++)
107
num_consec++;
108
109
if (num_consec == 5) {
110
straight = TRUE;
111
return;
112
}
113
114
for (rank = 0; rank < NUM_RANKS; rank++) {
115
if (facesInHand[rank] == 4)
116
four = TRUE;
117
if (facesInHand[rank] == 3)
118
three = TRUE;
119
if (facesInHand[rank] == 2)
120
pairs++;
121
}
122
NOw you can declare the winner easly by using this code
void printResults(int suitsInHand[], int facesInHand[], int *pointValue)
123
014
int straight, flush, four, three;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.