Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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!!!!

  1. a proper constructor that creates an empty Hand
  2. 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
  3. 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 card = new ArrayList<>(); String suit; Random rand = new Random(); public Deck() { for(int s = 1;s<=4;s++) { switch(s) { case 1: suit = "\u2660"; break; case 2: suit = "\u2665"; break; case 3: suit = "\u2663"; break; case 4: suit = "\u2666"; break; } for(int r =2;r<=14;r++) { card.add(new Card(r,s)); } } } public ArrayList shuffleTheseCards() { Card c1; Card c2; for (int i = 0; i

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

Intelligent Databases Object Oriented Deductive Hypermedia Technologies

Authors: Kamran Parsaye, Mark Chignell, Setrag Khoshafian, Harry Wong

1st Edition

0471503452, 978-0471503453

More Books

Students also viewed these Databases questions