Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Below i copied all my classes (please let me know if that is the wrong way to do it) and my question is how to

Below i copied all my classes (please let me know if that is the wrong way to do it) and my question is how to create a driver that

1. Shuffle the deck/deal four hands.

2. Display the four hands.

3. Declare the winning hand. the player and the hand that they won with

4. Ask if they want to play another hand.

public class Card { private final Suit suit; private final Rank rank; public Card(Rank newRank, Suit newSuit) { this.rank = newRank; this.suit = newSuit; }// ending bracket constructor

public Rank getRank() { return this.rank; }// ending bracket method getRank public Suit getSuit() { return this.suit; }// ending bracket method getSuit public String toString() { return this.rank.getRank() + " of " + this.suit.getSuit(); }// ending bracket method toString public String toStringSymbol() { return this.rank.getSymbol() + " of " + this.suit.getSymbol(); }// ending bracket method toStringSymbol public int getRankValue() { return this.rank.ordinal() + 2; }// ending bracket method getRankValue public boolean isSameSuit(Card otherCard) { return (this.getSuit() == otherCard.getSuit()); }// ending bracket method issamesuit public boolean isSameRank(Card otherCard) { return (this.getRank() == otherCard.getRank()); }//ending b racket method issamerank }// ending bracket class Card

// -----------------------------------------------------------------------------------------------------

import java.util.Random; import java.util.Random;

public class Deck { private Card[] cards; private static final int DECK_SIZE = 52; private Random randomizer; public Deck() { int arrayIndex = 0; this.cards = new Card[DECK_SIZE]; this.randomizer = new Random(); for (Suit suit : Suit.values()){ for (Rank rank : Rank.values()) { cards[arrayIndex++] = new Card(rank, suit); }// ending bracket inner foreach loop - rank }// ending bracket outter foreach loop -suit }// ending bracket constructor public void displayDeck() { for(Card card : cards){ System.out.println(card.toString()); }// ending bracket for loop }// ending bracket method display deck public void displayDeckSymbols() { for(Card card : cards) { System.out.println(card.toStringSymbol()); }// ending bracket for loop }// ending bracket method display symbols }// ending bracket class Deck

//--------------------------------------------------------------------------------------

public class Hand { private Card[] cards; private int currentNumberOfCards; private static final String COMMA_SPACE = ", "; public Hand(int numberOfCardsToHold){ this.cards = new Card[numberOfCardsToHold]; this.currentNumberOfCards = 0; }// ending bracket of constructor public void sort(){ boolean isNotSorted = true; Card tempCard = null; while(isNotSorted){ isNotSorted = false; for(int i = 0; i < this.cards.length - 1; ++i){ if(this.cards[i].getRankValue() < this.cards[i+1].getRankValue()){ tempCard = this.cards[i]; this.cards[i] = this.cards[i+1]; this.cards[i+1] = tempCard; isNotSorted = true; }// ending bracket if statement }// ending bracket for loop }// ending bracket of while loop }// ending bracket method sort public void addCard(Card newCard){ this.cards[this.currentNumberOfCards] = newCard; this.currentNumberOfCards++; }// ending bracket add card public String toString(){ StringBuffer sb = new StringBuffer(); for(Card card : this.cards){ // append means to add at the end sb.append(card.toString()); sb.append(COMMA_SPACE); }// ending bracket foreach loop return sb.toString(); }// ending bracket toString() public String toStringSymbol(){ StringBuffer sb = new StringBuffer(); for(Card card : this.cards){ // append means to add to end // sb.append(card.toStringSymbol()); sb.append(COMMA_SPACE); }// ending bracket foreach loop return sb.toString(); }// ending bracket toStringSymbol() }// ending bracket class Hand

//----------------------------------------------------------------------------------------

public enum Rank { DEUCE("Deuce", '2'), TREY("Trey", '3'), FOUR("Four", '4'), FIVE("Five", '5'), SIX("Six", '6'), SEVEN("Seven", '7'), EIGHT("Eight", '8'), NINE("Nine", '9'), TEN("Ten", 'T'), JACK("Jack", 'J'), QUEEN("Queen", 'Q'), KING("King", 'K'), ACE("Ace", 'A'); private String rank; private char symbol; private Rank(String newRank, char newSymbol) { this.rank = newRank; this.symbol = newSymbol; }// ending bracket constructor public String getRank() { return this.rank; }// ending bracket method getrank public char getSymbol() { return this.symbol; }// ending bracket getSymbol }// ending bracket enum Rank

//---------------------------------------------------

public enum Suit { HEARTS("Hearts", '\u2665'), DIAMONDS("Diamonds", '\u2666'), CLUBS("Clubs", '\u2663'), SPADES("Spades", '\u2660'); private String suit; private char symbol; private Suit(String newSuit, char newSymbol) { this.suit = newSuit; this.symbol = newSymbol; }// ending bracket constructor public String getSuit() { return this.name(); }// ending bracket method get name public char getSymbol() { return this.symbol; }// ending bracket getSymbol }// ending bracket enum Suit

//------------------------------------------------------------------------------------

public class Players {

private String name; private Hand hand; public Players(String newName, int numberOfCards){ this.setName(newName); this.setHand(new Hand(numberOfCards)); }// ending bracket constructor // PASS THROUGH METHOD public void addCard(Card newCard){ this.hand.addCard(newCard); }// ending bracket of pass through method public String getName(){ return this.name; }// ending bracket for method getname

public void setName(String newName){ name = newName; }// ending bracket for method setname public Hand getHand(){ return this.hand; }// ending bracket getHand public void setHand(Hand newHand){ this.hand = newHand; }// ending bracket setHand }// ending bracket class players

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2022 Grenoble France September 19 23 2022 Proceedings Part 4 Lnai 13716

Authors: Massih-Reza Amini ,Stephane Canu ,Asja Fischer ,Tias Guns ,Petra Kralj Novak ,Grigorios Tsoumakas

1st Edition

3031264118, 978-3031264115

More Books

Students also viewed these Databases questions

Question

4. Identify cultural variations in communication style.

Answered: 1 week ago

Question

9. Understand the phenomenon of code switching and interlanguage.

Answered: 1 week ago

Question

8. Explain the difference between translation and interpretation.

Answered: 1 week ago