Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public abstract class Card implements Comparable { /* handy arrays for ranks and suits */ public final static String[] RANKS = { None, Joker, 2,

image text in transcribed

image text in transcribed

image text in transcribed

public abstract class Card implements Comparable{

/* handy arrays for ranks and suits */ public final static String[] RANKS = { "None", "Joker", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace"}; public final static String[] SUITS = { "Diamonds", "Clubs", "Hearts", "Spades", "NONE"}; protected String suit; protected String rank;

// creates a card with specified suit and rank

public Card(String suit, int rank){ this.suit = suit; this.rank = RANKS[rank]; }

public Card(String suit, String rank){ // add code here if needed this.suit = suit; this.rank = rank; }

public abstract int getRank();

// the string representation of the rank of the current card

public abstract String getRankString();

// the suit of the current card

public abstract String getSuit();

@Override public final String toString(){ // outputs a string representation of a card object int r = getRank(); if( r >= 2 && r

}

import java.util.ArrayList; import java.util.List;

public class Deck{ protected List deck; public Deck(){ this(0); }

public Deck(int num_jokers){ deck = new ArrayList(52 + num_jokers); for (int i = 2; i

// testing for (int i=0; i

} public List getCards(int num_cards){ List removedCards = new ArrayList(num_cards); for (int i=0; i

// testing for (int i=0; i

public Card getCard(){ Card removedCard=deck.get(0); deck.remove(0 ); System.out.println(removedCard.getRank() + removedCard.getSuit()); for (int i=0; i

public void addCard(Card c){ deck.add((StandardCard) c); for (int i=0; i

}

import java.util.List;

public class Hand{ protected List cards;

public Hand(List cards){ this.cards = cards; }

public int numberOfCards(){ if( this.cards == null ){ return -1; }else{ return this.cards.size(); } }

public List getCards(){ return this.cards; }

public Card remove(Card card){ Card cardtoReturn = null; for (int i=0;i

/* add the specified card to the hand */ public void add(Card card){ this.cards.add(card); }

}

public abstract class Player{ protected Hand hand;

public Player(Hand hand){ this.hand = hand; }

public abstract Card play(Card top_of_discard_pile, Deck deck);

public final int cardsLeft(){ return this.hand.numberOfCards(); }

}

public class StandardCard extends Card implements Comparable{ public StandardCard(String rank, String suit) { super(suit,rank); for (int i = 0; i

public StandardCard(int rank, String suit) { super(suit,rank); if (rank != 1) { for (int i = 0; i

public int getSuitInt(String suit) { int suitInt = 0; for (int i = 0; i

@Override public String getRankString() { return this.rank; }

@Override public String getSuit() { return this.suit; }

@Override public int compareTo(Card o) { // int suitofFirstCard = 0; // int suitofSecondCard = 0; int rankofFirstCard = this.getRank(); int rankofSecondCard = o.getRank(); int value = 0; int suitofFirstCard = getSuitInt(this.getSuit()); int suitofSecondCard = getSuitInt(o.getSuit());

// for (int i = 0; i

if (suitofFirstCard > suitofSecondCard){ value = 1; } else if (suitofFirstCard rankofSecondCard){ value = 1; } else { value = -1; } } return value; }

public static void main (String[] args) { // int counter = 0; // for (int i = 1; i

hand.add(c); System.out.println(hand.getCards()); hand.remove(c); System.out.println(hand.getCards()); }

}

Complete the Hand class that is provided. You need to implement two methods (remove and add). You do not need to add very much code to this class. Complete the Hand class that is provided. You need to implement two methods (remove and add). You do not need to add very much code to this class

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

Data Analysis In Microsoft Excel

Authors: Alex Holloway

1st Edition

B0CCCPKTTX, 979-8852388452

More Books

Students also viewed these Databases questions

Question

=+1 Interpret the R2 of this regression model.

Answered: 1 week ago