Question
Create a class to model a hand of 13 Cards. Your Hand class will have a private instance variable that is an ArrayList-of-Card , and
Create a class to model a hand of 13 Cards. Your Hand class will have a private instance variable that is an ArrayList-of-Card, and these methods:
NO ARRAYS, ONLY ARRAYLIST!!!!
- a proper constructor that creates an empty Hand
- a method to fill a Hand with 13 Cards dealt from a Deck, with each one being inserted in its proper place in the Hand
- a toString method that returns a String representation of the Hand (Hint: call the Card class toString method for each Card in the Hand)
Card Class:
public class Card { private int rank; private int suit; private String s; public Card(int r,int s ) { if(rank>=2||rank<=10) { this.rank = r; this.suit = s; } } public int getRank() { return rank; } public int getSuit() { return suit; } @Override public String toString() { String r = "",s = ""; if(rank>=2 && rank<=10) { r = rank+""; } else if(rank == 11) { r="J"; } else if(rank == 12) { r = "Q"; } else if(rank == 13) r = "K"; else if(rank == 14) r = "A"; switch(suit) { case 1: s = "\u2660"; break; case 2: s = "\u2665"; break; case 3: s = "\u2663"; break; case 4: s = "\u2666"; break; } return r + s; } }
Deck Class:
public class Deck { private ArrayList
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