Question: Please complete the program. This is the code I have so far: /** * This program contains methods for a card game */ /** *

Please complete the program.

This is the code I have so far:

/**

* This program contains methods for a card game

*/

/**

* @author

*

*/

public class Cards {

/**

* @param args

*/

public static void main(String[] args) {

int[] hand = Cards.dealHand(2); //will only be dealing with 2 cards per hand

System.out.print(hand[0] + " " + hand[1]);

}

public static int[] dealHand(int n) {

int[] hand = new int[n];

int rand;

int max = 51;

int min = 0;

int range = max - min + 1;

do{

for (int i = 0; i

rand = (int) (Math.random()* range) + min;

hand[i] = rand;

}

} while (hand[0] == hand[1]);

return hand;

}

public static char suit(int card) { //Assigns suit based on int val

char suit;

if (0

suit = 'H';

}else if (13

suit = 'S';

}else if (26

suit = 'D';

}else if (39

suit ='C';

} else {

suit = 'x';

}

return suit;

}

public static int rank(int card) { //Assigns rank based on int val, 1 is ace and 13 is king

int cardValue = 0;

if (card == 0 || card == 13 || card == 26 || card == 39) {

cardValue = 1;

}else if (card == 1 || card == 14 || card == 27 || card == 40) {

cardValue = 2;

}else if (card == 2 || card == 15 || card == 28 || card == 41) {

cardValue = 3;

}else if (card == 3 || card == 16 || card == 29 || card == 42) {

cardValue = 4;

}else if (card == 4 || card == 17 || card == 30 || card == 43) {

cardValue = 5;

}else if (card == 5 || card == 18 || card == 31 || card == 44) {

cardValue = 6;

}else if (card == 6 || card == 19 || card == 32 || card == 45) {

cardValue = 7;

}else if (card == 7 || card == 20 || card == 33 || card == 46) {

cardValue = 8;

}else if (card == 8 || card == 21 || card == 34 || card == 47) {

cardValue = 9;

}else if (card == 9 || card == 22 || card == 35 || card == 48) {

cardValue = 10;

}else if (card == 10 || card == 23 || card == 36 || card == 49) {

cardValue = 11;

}else if (card == 11 || card == 24 || card == 37 || card == 50) {

cardValue = 12;

}else if (card == 12 || card == 25 || card == 38 || card == 51) {

cardValue = 13;

}

return cardValue;

}

public static void printCard(int card) { //takes dealHand, uses rank and suit method

}

public static void printHand(int[] hand) { //

}

}

Rest of program:

Once you have cards in your hand, you need a way to print them out to show the user, so you need two methods, one will use the other.

public static void printCard(int card)

public static void printHand(int[] hand)

You will be able to find out the rank of the card using the rank() method you already wrote, but it wont make sense to print a number from 1 to 13. String s = A23456789TJQK and the s.charAt() method will help you print a character that makes sense.

Next, you need to evaluate the hand. Write the following methods:

public static boolean isPair(int[] hand)

public static boolean isStraight(int[] hand)

public static boolean isFlush(int[] hand)

public static boolean isJackOrHigher(int[] hand)

Finally (for this part of the lab), you will test your methods in the main() method. Run it several times to verify it works. If you want to construct specific hands (int[]s), you can also test it that way. You can put this main() in the Cards.java file or a different file in the same folder. Remember that A-2 and K-A are both straights; you will need some special logic for this case.

public static void main(String[] args)

{

int[] hand = Cards.dealHand(2);

Cards.printHand(hand);

System.out.println(isPair? + Cards.isPair(hand));

System.out.println(isStraight? + Cards.isStraight(hand));

System.out.println(isFlush? + Cards.isFlush(hand));

System.out.println(isJacks? + Cards.isJackOrHigher(hand));

hand = new int[] = { 13, 26 };

Cards.printHand(hand);

System.out.println(isPair? + Cards.isPair(hand));

System.out.println(isStraight? + Cards.isStraight(hand));

System.out.println(isFlush? + Cards.isFlush(hand));

System.out.println(isJacks? + Cards.isJackOrHigher(hand));

}

Please complete the program. This is the code I have so far:

Example output: 5/H 9/H isPair? false isStraight? false isFlush? true SJacks? false A/S A/D isPair? true isStraight? false isFlush? false isJacks? true 2/C 2/D isPair? true isStraight? false isFlush? false SJacks? false A/S A/D isPair? true isStraight? false isFlush? false isJacks? true 4/H 3/H isPair? false isStraight? true isFlush? true SJacks? false A/S A/D isPair? true isStraight? false isFlush? false isJacks? true Example output: 5/H 9/H isPair? false isStraight? false isFlush? true SJacks? false A/S A/D isPair? true isStraight? false isFlush? false isJacks? true 2/C 2/D isPair? true isStraight? false isFlush? false SJacks? false A/S A/D isPair? true isStraight? false isFlush? false isJacks? true 4/H 3/H isPair? false isStraight? true isFlush? true SJacks? false A/S A/D isPair? true isStraight? false isFlush? false isJacks? true

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!