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

Need help with this class. Code public class Card { String faceValue; String sui

ID: 3742940 • Letter: N

Question

Need help with this class.

Code

public class Card {

String faceValue;

String suit;

public Card(String faceValue, String suit) {

super();

this.faceValue = faceValue;

this.suit = suit;

}

public String getFaceValue() {

return faceValue;

}

public String getSuit() {

return suit;

}

public String tostring(Card c){

String faceValue = c.getFaceValue();

String suit = c.getSuit();

if(suit.equals("Spade"))

suit="u2660";

if(suit.equals("Club"))

suit="u2663";

if(suit.equals("Heart"))

suit="u2665";

if(suit.equals("Diamond"))

suit="u2666";

return faceValue + suit;

}

}

------------------------------------------Deck Class------------------------------------------------------------

class Deck {

public static final int NCARDS = 52;

private Card[] deckOfCards;

public Deck(){

deckOfCards = new Card[NCARDS];

String suit="";

String faceValue;

int count =0;

for(int i=1;i<=4;i++){

if(i==1)

suit="Spade";

if(i==2)

suit="Club";

if(i==3)

suit="Heart";

if(i==4)

suit="Diamond";

for(int j=1;j<=13;j++){

switch (j) {

case 1:

faceValue = "2";

break;

case 2:

faceValue = "3";

break;

case 3:

faceValue = "4";

break;

case 4:

faceValue = "5";

break;

case 5:

faceValue = "6";

break;

case 6:

faceValue = "7";

break;

case 7:

faceValue = "8";

break;

case 8:

faceValue = "9";

break;

case 9:

faceValue = "10";

break;

case 10:

faceValue = "J";

break;

case 11:

faceValue = "Q";

break;

case 12:

faceValue = "K";

break;

case 13:

faceValue = "A";

break;

default:

faceValue = "Invalid";

break;

}

deckOfCards[count++] = new Card(faceValue,suit);

}

}

}

public void printDeck(){

for(int i=0;i<NCARDS;i++){

System.out.println(deckOfCards[i].tostring(deckOfCards[i]));

}

}

public Card getCard(int num){

return deckOfCards[num];

}

}

---------------------------------------------------Hand Class---------------------------------------------------------

import java.util.HashSet;

import java.util.Iterator;

import java.util.Random;

import java.util.Set;

class Hand{

private Card[] handOfCards;

int number;

public Hand(int number){

this.number=number;

Deck d= new Deck();

handOfCards = new Card[number];

Random random = new Random();

Set set = new HashSet<Integer>(number);

while(set.size()< number) {

while (set.add(random.nextInt(52)) != true);

}

assert set.size() == number;

Iterator<Integer> itr = set.iterator();

int count = 0;

while(itr.hasNext()){

handOfCards[count++] = d.getCard(itr.next());

}

}

public void printHandOfCards(){

for(int i=0;i<number;i++)

System.out.println(handOfCards[i].tostring(handOfCards[i]));

}

}

Che Hand) V. The Test Class 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 asa 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 Java's 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 S. Make rure your Deck., kand, and Card lagees all contain proper Java "documentation comments" and adhere to all the style and internal documentation standards discussed in class and covered in Unit l

Explanation / Answer

As you have asked only Test class, So prividing the test class only. You can change the value of NUMBER_OF_CARDS_IN_HAND to any number to change number of cards in Hand.

import java.util.Scanner;

public class Test {

static final int NUMBER_OF_CARDS_IN_HAND = 5;

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

String printAnother = "Y";

while (printAnother.equalsIgnoreCase("Y")) {

printHand();

System.out.println("Do you want to see another hand? <Y/N>");

printAnother = sc.next();

}

sc.close();

}

public static void printHand() {

Hand hand = new Hand(NUMBER_OF_CARDS_IN_HAND);

System.out.println("Hand: ");

hand.printHandOfCards();

}

}

Output

Hand:
3?
A?
10?
2?
4?
Do you want to see another hand? <Y/N>
Y
Hand:
Q?
2?
7?
7?
6?
Do you want to see another hand? <Y/N>
Y
Hand:
J?
10?
J?
4?
9?
Do you want to see another hand? <Y/N>
N