Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

//Provided Card Class public class Card { private Face name; private Suit suit; public Card(Face name, Suit suit) { this.name = name; this.suit = suit;

image text in transcribed

//Provided Card Class

public class Card { private Face name; private Suit suit;

public Card(Face name, Suit suit) { this.name = name; this.suit = suit; }

public Face getName() { return name; }

public Suit getSuit() { return suit; }

public int rank() { return name.getRank(); }

public int value() { return name.value(); }

public String toString() { return String.format("%5s of %s", name.toString(), suit.toString()); }

/** * Compare the ranks of two cards. * @return a value less than 0 if the rank of 'this' card is less than the one passed in, 0 if * the ranks of the cards are equal and a value greater than 0 if the rank of 'this' card is * greater than the rank of the one passed in. * * Note: This method works ONLY if another Card object is passed in as a parameter. */ public int compareTo(Object other) { return this.name.getRank() - ((Card)other).name.getRank(); }

public static void main(String args[]) {

Card one = new Card(Face.QUEEN, Suit.HEARTS); Card two = new Card(Face.JACK, Suit.DIAMONDS);

if (one.compareTo(two) 0) { System.out.println(one + " \tis greater than " + two); } else { System.out.println(one + " and " + two + " ARE EQUAL");; } } }

//Provided Tester Class

public class Tester { private Hand one; private Hand two;

public Tester() { one = new Hand(); two = new Hand(5); }

public void makeSF(Hand hand) { hand.setCard(4, new Card(Face.KING, Suit.DIAMONDS)); hand.setCard(3, new Card(Face.QUEEN, Suit.DIAMONDS)); hand.setCard(2, new Card(Face.JACK, Suit.DIAMONDS)); hand.setCard(1, new Card(Face.TEN, Suit.DIAMONDS)); hand.setCard(0, new Card(Face.NINE, Suit.DIAMONDS)); }

public void make4K(Hand hand) { hand.setCard(0, new Card(Face.FIVE, Suit.DIAMONDS)); hand.setCard(1, new Card(Face.FIVE, Suit.SPADES)); hand.setCard(2, new Card(Face.FIVE, Suit.CLUBS)); hand.setCard(3, new Card(Face.FIVE, Suit.HEARTS)); hand.setCard(4, new Card(Face.THREE, Suit.DIAMONDS)); } public void make3K(Hand hand) { hand.setCard(0, new Card(Face.ACE, Suit.SPADES)); hand.setCard(1, new Card(Face.EIGHT, Suit.CLUBS)); hand.setCard(2, new Card(Face.EIGHT, Suit.HEARTS)); hand.setCard(3, new Card(Face.EIGHT, Suit.DIAMONDS)); hand.setCard(4, new Card(Face.KING, Suit.DIAMONDS)); } public void make3K2(Hand hand) { hand.setCard(0, new Card(Face.THREE, Suit.DIAMONDS)); hand.setCard(1, new Card(Face.THREE, Suit.SPADES)); hand.setCard(2, new Card(Face.THREE, Suit.CLUBS)); hand.setCard(3, new Card(Face.FOUR, Suit.HEARTS)); hand.setCard(4, new Card(Face.QUEEN, Suit.DIAMONDS)); } public void makeFH(Hand hand) { hand.setCard(0, new Card(Face.THREE, Suit.DIAMONDS)); hand.setCard(1, new Card(Face.THREE, Suit.SPADES)); hand.setCard(2, new Card(Face.THREE, Suit.CLUBS)); hand.setCard(3, new Card(Face.QUEEN, Suit.HEARTS)); hand.setCard(4, new Card(Face.QUEEN, Suit.DIAMONDS)); } public void makeS(Hand hand) { hand.setCard(0, new Card(Face.THREE, Suit.DIAMONDS)); hand.setCard(1, new Card(Face.FOUR, Suit.SPADES)); hand.setCard(2, new Card(Face.FIVE, Suit.CLUBS)); hand.setCard(3, new Card(Face.SIX, Suit.HEARTS)); hand.setCard(4, new Card(Face.SEVEN, Suit.DIAMONDS)); } public void makeS2(Hand hand) { hand.setCard(0, new Card(Face.FIVE, Suit.DIAMONDS)); hand.setCard(1, new Card(Face.SIX, Suit.SPADES)); hand.setCard(2, new Card(Face.SEVEN, Suit.CLUBS)); hand.setCard(3, new Card(Face.EIGHT, Suit.HEARTS)); hand.setCard(4, new Card(Face.NINE, Suit.DIAMONDS)); }

public void make2P(Hand hand) { hand.setCard(0, new Card(Face.ACE, Suit.DIAMONDS)); hand.setCard(1, new Card(Face.FOUR, Suit.SPADES)); hand.setCard(2, new Card(Face.FOUR, Suit.CLUBS)); hand.setCard(3, new Card(Face.TEN, Suit.HEARTS)); hand.setCard(4, new Card(Face.TEN, Suit.DIAMONDS)); } public void makeP(Hand hand) { hand.setCard(0, new Card(Face.ACE, Suit.DIAMONDS)); hand.setCard(1, new Card(Face.THREE, Suit.SPADES)); hand.setCard(2, new Card(Face.FOUR, Suit.CLUBS)); hand.setCard(3, new Card(Face.TEN, Suit.CLUBS)); hand.setCard(4, new Card(Face.TEN, Suit.SPADES)); } public void makeH(Hand hand) { hand.setCard(0, new Card(Face.ACE, Suit.DIAMONDS)); hand.setCard(1, new Card(Face.THREE, Suit.SPADES)); hand.setCard(2, new Card(Face.FOUR, Suit.CLUBS)); hand.setCard(3, new Card(Face.SEVEN, Suit.CLUBS)); hand.setCard(4, new Card(Face.TEN, Suit.SPADES)); }

public void go() {

// Create a new array that holds 8 hands // Loop through the array and fill it with a new hand (no parameters)

// Call makeSF with a hand index of 0 // Call make4K with a hand index of 1 // Call make3K with a hand index of 2 // Call makeFH with a hand index of 3 // Call makeS with a hand index of 4 // Call make2P with a hand index of 5 // Call makeP with a hand index of 6 // Call makeH with a hand index of 7

// Loop through the hand array and call the sort method for the hand // at each index // Finish the following statements so that the appropriate hand type is // printed for each index of hand System.out.println("SF: "); System.out.println("4K: "); System.out.println("3K: "); System.out.println("FH: "); System.out.println("S: "); System.out.println("2P: "); System.out.println("P: "); System.out.println("H: ");

}

public static void main(String[] args) { // Create a new Tester object and call its go() method } }

Overview Write a program that plays a hand of five card draw (a bazic Poker variant) between one player and the computer. Your program should use the following rules: . When the hands are first dealt display player cards, but not the computer cards. After the discard, display both hands. After the discards, display both hands, print the game winner and the wimming hard. Supplied is the card class, and a Tester class to check your code can identify the diferent win hands Information You will need the following enumerations: 1. Suit - model the suit of a card Mfast work with the supplied Cand 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) - must work with the Card dass. When you built the card showdown lab, the face enumeration did not include the rank it should now All card points are the face value of the card where Ace is 1 and Ten of clubs is a 10. All picture cards are worth 10 points. 3. JinHand - models the winning hands of poker as well as an invalid state. It must detect the following hands (shown in order of rank). Below is a picture of the different hand combinations. 1. Royal Flush AK QJ 10 10 9 8 7 6 2. Straight flush ROYAL FLUSH STRAIGHT FLUSH 3. Four of a kind Bulbouse AAAA K88 KQ 0985 9 8 7 6 5 Stricht 2+. +++++ 5. Straight FOUR OF A KIND FULL HOUSE FLUSH STRAIGHT 6. Flush 7. Three of a kind 3 J J 38 0 0 7 7 3 AA3 8 10 .. +++ 8. Two pair THREE OF A KINO TWO PAIRS ONE PAIR High Card 9 Pair 10. HelCard in the absence of all other hands, high card wins) thos You will need the following Classes 1. Card - models a playing card. (This class is supplied) 2. Hand-models a hand of five card draw. (This class is partly supplied) Fields: Whatever fields are needed to represent a single hand of cards for one player. You must use an array for your Cards. il fields must be private . Constructor that accept the number of cards in a hand. A po-parameter constructor that creates an array that can hold 5 cards. This constructor must call the other constructor to accomplish its goal. .setCard - sets a single card in the hand. (you can think of it as replace). The method has two parameters the first the index of the card to replace, second the new Card (in that order please) .getHandlaze returns a reference to a Willos, emmeration representing the type of hand this is. To do this it has to call several belper methods outlined below. It is mblic method. . The following is a set of methods for detecting each type of win For the methods that retum an int representing a pair three or four of a kind, retum Owen no such situation OCCOUGA PetPair - retums an int representing the rank of the cards comprising the pair in this hand. If there are two pairs retum the highest one. 2ebreekind -retums an int representing the rank of the cards comprising the three of a kind in this hand setFgurind - retums an int representing the rank of the cards comprising the four of a kind in this hand etHighe:Card-retums the highest Card in this hand public method) walFlush. - A belper method that returns true if the hand contains a royal flush straightlusb-helper method that retums true if the hand contains a straight flush. straight - helper method that retums true if the hand contains a straight flush - A helper method that retums true if all cards are of the same suit four Of A Kind - helper method that retums true if the hand contains a four of a kind. the QAKind - helper method that returns true if the hand contains a three of a kind pair - helper method that retums true if the hand contains a pair. Pait - helper method that returns true if the hand contains two pairs. full HQER-helper method that retum: true if the hand contains a full house. .toString - returns a string indicating each cards as well as a mmber 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 erzierl. Use the following code: Note this only works in Java 8: Ana sort(cards, (Card ul. Card 12) ul.compareTo(1.2)): You will also need to import java.uti. Anas 3. Game - models are 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 Hanil. Constants needed to avoid magic mmbers, and other fields you deem necessary! No parameter constructor - initialized all the fields. shuffle - the Fisher-Yates Shuffle. diarlas Hand-prints out a player's (computer or player) hand of cards in a nicely formatted fashion . deal - method that deals two hands of cards. 15 32 deal Ope- deals one cards to a specific location in a hand of a player computer or player). 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! printumuer - prints our who won the game and what hand they had .main-should create a Game object and call the go method . There is no betting for this game

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

From Zero To Data Hero With Chatgpt

Authors: Andrew Wu

1st Edition

B0CQRJPXD9, 979-8989523009

More Books

Students also viewed these Databases questions

Question

Describe the seven standard parts of a letter.

Answered: 1 week ago

Question

Explain how to develop effective Internet-based messages.

Answered: 1 week ago

Question

Identify the advantages and disadvantages of written messages.

Answered: 1 week ago