Answered step by step
Verified Expert Solution
Question
1 Approved Answer
3: Hand of Cards Complete the Hand class that is provided. You need to implement two methods (remove and add). You do not need to
3: Hand of Cards 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.
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; } /* remove and return the specified card from the hand */ /* return null if the card is not in the hand */ public Card remove(Card card){return new StandardCard(Card.SUITS[4], Card.RANKS[1]);} /* add the specified card to the hand */ public void add(Card card){} }
EDIT: My apologies, here is the card class:
public abstract class Card implements Comparable{ private int rank; private int suit; /* handy arrays for ranks and suits */ /* do NOT change these */ 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"}; /** creates a card with specified suit and rank * * @param suit is the suit of the card (must be a string from Card.SUITS) * @param rank is the rank of the card (must be a string from Card.RANKS) */ public Card(String suit, String rank){ // add code here if needed } /** the numerical representation of the rank of the current card * * ranks have the numerical values * Joker = 1, * 2 = 2, 3 = 3, ..., 10 = 10 * Jack = 11, Queen = 12, King = 13, Ace = 14 * * @return the numerical rank of this card */ public abstract int getRank(); /** the string representation of the rank of the current card * * @return the string representation of the rank of this card (must be a string from Card.RANKS) */ public abstract String getRankString(); /** the suit of the current card * * @return the suit of this card (must be a string from Card.SUITS) */ public abstract String getSuit(); @Override public final String toString(){ // outputs a string representation of a card object int r = getRank(); if( r >= 2 && r <= 14 ){ return r + getSuit().substring(0,1); } if (r == 1){ return "J"; } return "invalid card"; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started