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

There are 52 cards in a deck; each belongs to one of four suits and one of 13 ra

ID: 3821610 • Letter: T

Question

There are 52 cards in a deck; each belongs to one of four suits and one of 13 ranks. The suits from the lowest to the highest importance are: Spades, Hearts, Diamonds and Clubs. The ranks are: Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen and King. The suits and ranks are mapped to two arrays of values as follows: int [] suits = {1, 2, 3, 4}; where 1 maps Spades; 2 maps Hearts; 3 maps Diamond; 4 maps Clubs int [] ranks = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; where 1 maps Ace; 2 maps 2; ... 11 maps Jack, ... Write the Java implementation of the classes Card, Deck, and Hand following the instructions below. The class Hand uses the ArrayList implementation of the abtract data type List to store the cards in the hand. Implement the method: public int total () that returns the total number of cards in the hand.

Explanation / Answer

import java.util.*; class Deck { // create possible card combinations public final String[] SUITS = { "H", "D", "C", "S" }; public final String[] RANKS = { "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3", "2" }; // maximum number of cards public final int deckLength = SUITS.length * RANKS.length; public List fullDeck = new ArrayList(); public Deck() { for(int i = 0; i