Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Card players typically like to keep the cards in their hand sorted by suit and within each suit by face value. Assuming that a hand

Card players typically like to keep the cards in their hand sorted by suit and within each suit by face value. Assuming that a hand consists of 13 cards, write a Java program to insert each card into an initially empty hand in the proper order, so that there is no need to sort the hand.

The order of the suits is unimportant but within each suit the order of the cards should be 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A (i.e. the Ace is always the high card).

II. The Card Class

Begin by creating a class to model a playing card. The Card class will have two private instance variables: (1) the face value (aka: rank) stored as ints 2..14 and (2) the suit (Spades, Hearts, Diamonds, Clubs).

Your Card class will have these methods:

    1. a proper constructor that creates a Card with a given rank and suit
    2. an accessor (get) method that returns the rank
    3. an accessor (get) method that returns the suit
    4. a toString method that returns a String representation of a card as shown in these examples: A, 10, 7, Q
  1. To get the symbols for the suits, use the escape sequences for the Unicode characters:

\u2660 (Spade) \u2663 (Club)

\u2665 (Heart) \u2666 (Diamond)

III. The Deck Class

Create a class to model a standard 52-card deck. Your Deck class will have a private instance variable that is an ArrayList-of-Card. (You may have additional instance vars although none are needed)

Your Deck class will have these methods:

  1. a proper constructor that creates a standard Deck of 52 cards
  2. a method that deals the top card. I.e. returns the Card object on top of the Deck
  3. a method that shuffles the deck. To get credit for this method you must use this algorithm:

for each card in the deck

exchange it with the card at a randomly-selected index

(to mix em up good you might want to shuffle the deck a number of times)

IV. The Hand Class

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:

  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)

V. The Test Class

Your test class will have a main method that creates a Hand, calls the method that fills it, calls the toString method for the Hand, and prints the String returned. After each Hand is displayed, ask the user if she wants to see another.

CAN ONLY USE ARRAYLIST NO OTHER DATA STRUCTURE!!!

NO COLLECTIONS CLASS EITHER.

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

Database Modeling And Design

Authors: Toby J. Teorey, Sam S. Lightstone, Tom Nadeau, H.V. Jagadish

5th Edition

0123820200, 978-0123820204

More Books

Students also viewed these Databases questions