Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment to be programmed in Java, and MUST use Arrays, NOT Arraylist The assignment is to create a standard deck of 52 cards, shuffle it,

Assignment to be programmed in Java, and MUST use Arrays, NOT Arraylist

The assignment is to create a standard deck of 52 cards, shuffle it, ask the user how many cards they want in their hand, and finally have the cards sorted in the hand by rank and value. The program must have 4 classes, the card class, deck class, hand class, and tester class.

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

Unicode characters: \u2660 (Spade) \u2663 (Club) \u2665 (Heart) \u2666 (Diamond)

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

remove it from the deck

insert it back at a random index.

The Hand Class

Create a class to model a hand of Cards. Your Hand class will have a private instance variable that is an Array-of-Card, and these methods:

  1. a proper constructor that creates an empty Hand
  2. a method to fill a Hand with however many cards the user request (ex 13 cards) 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)

The Tester Class

The 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. Also prompt the user to specify the size of each hand (assume correct input).

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_2

Step: 3

blur-text-image_3

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 Management Databases And Organizations

Authors: Richard T. Watson

2nd Edition

0471180742, 978-0471180746

More Books

Students also viewed these Databases questions

Question

advertising expense is a _____ that is reported on the ______

Answered: 1 week ago