import java.util.*; public class CardGame { public static void main(String[] args) { Random g = new Random(); Scanner in=new Scanner(System.in); int[] hand=new int[3]; int amount=200; char answer='y'; boolean[] deck=new boolean[52]; do { shuffle(deck); deal(hand, deck, g); amount=amount-30; // change this amount if you want a game to cost more than $30 amount=amount-draw(hand, deck, g, in)*20; // change the 20 if you want each additional card to cost more than $20 sort(hand); // sorts the cards in order to make it easier to determine what the player has display(hand); // display the cards in the hand amount=amount+evaluate(hand); // evaluate will return the amount won for the hand if(amount>0) // if user still has money to play, ask if he/she wants to play again answer=JOptionPane.showInputDialog("You now have $" + amount + "\nPlay again?").toLowerCase().charAt(0); }while(amount>0&&answer=='y'); System.out.println("You leave us with $" + amount + "\nThanks for playing"); } public static int draw(int[] h, boolean[] d, Random g, Scanner in) { // display the hand to the user and ask if they want to exchange a card (ask which card, 0, 1, 2 or 3 where 0 means do not exchange any. // if they respond with 1, 2, or 3, subtract 1 from this value so it maps into the h array // draw a card from the deck randomly, making sure that the card has not been dealt before (use the boolean array d) // once you have a card, set d[cardlocation] to true // replace the card in h with the new card (for instance, if you want to replace h[1] then you would do h[1]=newCard;) // add 1 to count to indicate that they exchanged a card // do the same steps again since they exchanged 1 card (they might want to do this again) return count; } public static String convert(int card) { String temp=""; // convert the int value of card to a String by: // card/4+2 to get the face value where 11=jack, 12=queen, 13=king, 14=ace // card%4 to get the suit, a remainder of 0 is clubs, 1 is diamonds, 2 is hearts and 3 is spades //For instance, card 31 is 31/4+2=9, 31%4=3, so it is the 9 of hearts. return temp; } public static int score(int[] h) { if(isStraight(h)) return 150; else if(isFlush(h)) return 100; else if(isThree(h)) return sum(h)*3+60; else if(isPair(h)) return sum(h)*2+20; else return sum(h); } public static int isStraight(int[] h) { // write the code to determine if the 3 cards in the hand are in sequence like 2, 3, 4, or 10, // jack, queen, aces can only be high, and if a straight is found, return 150, otherwise // return 0 } public static int isFlush(int[] h) { // write the code to determine if the 3 cards in the hand have the same suit and if so, // return 100 else return 0 } public static int isThree(int[] h) { // write the code to determine if the 3 cards are all the same value and if so, // return value * 3 + 60 (for instance, 3 9's would be 3 * 9 + 60), else return 0 } public static int isPair(int[] h) { // write the code to determine if 2 of the 3 cards are the same and if so, return // sum of 3 cards * 2 + 20 (for instance, 2 Aces and an 8 would return (14 + 14 + 8) * // 2 + 20 = 92) } public static int sum(int[] h) { // sum up the face values of the 3 cards and return this sum } public static void sort(int[] h) { int temp; int c0=h[0]/4, c1=h[1]/4, c2=h[2]/4; if(c00) return isStraight(h); // else if(isFlush(h)>0) return isFlush(h); etc... } public static void display(int[] h) { // write the code to output the contents of the hand in the form: 3 of Hearts, Jack of Spades, Queen of Spades } public static void shuffle(boolean[] d) { // this sets all of the cards as having not been dealt yet (all in the deck) for(int i=0;i<52;i++) d[i]=false; } public static int getCard(boolean[] d, Random g) { // write the code to generate a new card (0-51) and make sure it has not yet been dealt, setting d[card] to true and returning card } public static void deal(int[] h, boolean[] d, Random g) { // deal an entire 3 card hand } }