Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a program that sorts a user\'s hand into ascending order, based upon the

ID: 3567901 • Letter: C

Question

Create a program that sorts a user's hand into ascending order, based upon the worth of each card in the hand. For this problem, you should ask your user to identify the cards in her hand, and then organize the cards for her in ascending order of worth. Note that, though the ace of any suit has the value "1," it should be considered the card with the highest worth. Cards should also be sorted so that clubs precede diamonds, diamonds precede hearts, and hearts precede spades.

Each card should be stored in a structure that can store the card's suit and the card's value. Each card has a suit and a value. The suit is represented as a character ('h' for hearts, 'd' for diamonds, 's' for spades, 'c' for clubs), and a value (2 - 10, plus 11 for jacks, 12 for queens, 13 for kings, and 1 for aces. ) All five structures are stored in, sorted in, and output from a single array.

Consider the following hand:

               card 1: 8 of clubs

               card 2: 2 of diamonds

               card 3: Ace of spades

               card 4: 8 of spades

               card 5: Ace of clubs

The hand sorted into ascending order would be output as:

               2 of diamonds

               8 of clubs

               8 of spades

               Ace of clubs

               Ace of spades

Output the hand.

Your program should use the following functions:

               - a function to fill an array with the values of the user's cards

               - a function to sort the hand into ascending order, based on card worth

               - a function to output the sorted hand

Explanation / Answer

public class PlayingCard implements Comparable { //face card values public static final int ACE = 1; public static final int JACK = 11; public static final int QUEEN = 12; public static final int KING = 13; public static final int JOKER = 0; //suits, in bridge rank order, highest to lowest public static final int SPADES = 4; public static final int HEARTS = 3; public static final int DIAMONDS = 2; public static final int CLUBS = 1; /** a null suit for Jokers or other non-suit cards */ public static final int NONE = 0; //instance variables private int value; //sometimes call pips private int suit; /** * Creates a new playing card. * Must be given a valid value and suit, or will create a JOKER/NONE card. * * @param value The value of the new card, from ACE (1) to KING (13), * or else JOKER. * @param suit A valid suit, such as HEARTS, SPADES, CLUBS, or DIAMONDS; * a JOKER has a suit of NONE. */ public PlayingCard(int value, int suit) { if (value >= 1 && value = 1 && suit
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote