Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

I.The Assignment

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 entire 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). To receive credit for this assignment, you must use the algorithm given below.

II. The CardClass

Begin by creating a class to model a playing card. Card objects know their face value (aka: rank) and their suit (Spades, Hearts, Diamonds, Clubs). Your Card class will have:

  1. a constructor that creates a Card with a given rank and suit
  2. accessor methods that return the rank and suit

3.atoStringmethod that returns a String representation of a card as shown in these examples: A, 10, 7, Q

To get the symbols for the suits, use the escape sequencesfor the Unicode characters:

\u2660 (Spade)

\u2663 (Club)

\u2665 (Heart)

\u2666 (Diamond)

III. The DeckClass

Your Deck class will model a standard 52-card deck. It will have a constructor that creates a Deck, and separate methods to:

1. deal the top card (returns a Card object)

2. shuffle the deck

Here is the shuffle algorithm you are to use:

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 random number of times)

IV. The HandClass

Your Hand class will model a hand of 13 cards. It will have a constructor that creates an empty Hand, and these methods:

1. a method to fill the Hand with 13 Card objects dealt from the Deck, with each one being inserted in its proper place in the Hand

2. a toStringmethod that returns a String representation of the Hand (Hint: call the Card class toStringmethod for each Card in the Hand)

V. The TestClass

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

Hint: to avoid having to pass the Deck to the Hand class as a parameter, create the Deck in the Hand class.

VI. Specifications

  1. You must use a generic ArrayList of Card as the implementation of the Deck and the Hand
  2. No credit will be given if any other data structures, including arrays, are used anywhere in the program, with one exception: you may use an ArrayList or array of String to store the suit names
  3. No credit for using any of the methods of Javas Collections class. Use the shuffle algorithm given
  4. Although the assignment calls for a hand of 13 cards, you should parameterize your program by using a defined constant for the number of cards in the hand. That way, you can generate hands of different sizes by making only one change
  5. Make sure your Deck, Hand, and Card classes all contain proper Java documentation comments and adhere to all the style and internal documentation standards discussed in class and covered in Unit 1

VII. What to Upload to Moodle

Upload a .zip file of your NetBeans project folder. Do not zip the individual .java files; zip the project folder. Include output showing 3 hands.

VIII. Due Date Tuesday, Sept 11th

  1. You will receive two separate grades for this assignment one for the program itself and one for the web pages created by javadoc
  2. To make sure you receive credit, review the Submitting Your Assignments and Creating a Zip File docs in the Before Beginning Unit online
  3. Do notzip the project from within NetBeans! If you do it will not contain the dist folder (where the html files are stored)
  4. See the algorithm on the next page

Algorithm to Create the Sorted Hand

Place the first card in the hand

For each additional card, do the following:

If the card is of a suit that has not appeared previously

Place it to the right of all the other cards

Otherwise, do the following:

If the value is higher than all the previous cards of that suit

Place it to the right of the other cards of that suit

Otherwise

Place it immediately to the left of the first card of that suit with a higher value

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

XML Data Management Native XML And XML Enabled Database Systems

Authors: Akmal Chaudhri, Awais Rashid, Roberto Zicari, John Fuller

1st Edition

ISBN: 0201844524, 978-0201844528

More Books

Students also viewed these Databases questions

Question

Absolute zero equals: O OOF. O 273 K. O O'C. O -273.C. O -400.F

Answered: 1 week ago