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

Suppose, 4 Players are playing a game of cards. Players are distributed cards fr

ID: 3885367 • Letter: S

Question

Suppose, 4 Players are playing a game of cards. Players are distributed cards from a standard 52-cards deck randomly. Before starting the game each player sorts the cards in their hand for convenience during the play. While sorting, a player first looks at the suits and groups same suits together. For this certain version of that game, the order of the value of suits is as follows: a. spades b. hearts c. diamonds d. clubs Among the same suit of cards the order of cards: A, K, Q, J, 10, 9, 8, 7, 6, 5, 4, 3, 2 Write a class Card Write a class Player that has a. An array of 13 cards b. A method to sort the array of cards (you can use the Insertion Sort shown in the class) A sample test program is given here: package hw.cse214.cards: public class CardSortingTest { public static void main(String[] args) { String[] cardsForPlayer1- { "S4", "D8", "C4", "D3", "DS", "DJ", "S3", "D4", "DA", "SJ", "D7", "H10", "D6" }: Card[] cards = new Card [13]: for (int i - 0: i

Explanation / Answer

Card.java

public class Card {


//Declaring instance variables
private String value;

//Parameterized constructor

public Card(String value2) {
this.value = value2;
}

//getters and setters

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}

}

_______________________

Player.java

public class Player {
// Creating Card class array
Card cards[];

// Declaring instance variables
private int id;

// Parameterized constructor
public Player(int id) {
super();
this.id = id;
}

// getters and setters
public Card[] getCards() {
return cards;
}

public void setCards(Card[] cards) {
this.cards = cards;
}

// This method will display the array of cards
public void printCards() {
for (int i = 0; i < cards.length; i++) {
System.out.print(cards[i].getValue() + " ");
}
System.out.println(" ");
}

// This method will sort the array of cards using insertion order
public void sortCards() {
for (int m = 1; m < cards.length; m++) {
String val = cards[m].getValue();
int n = m - 1;
while ((n > -1) && (cards[n].getValue().compareTo(val)) < 0) {
cards[n + 1].setValue(cards[n].getValue());
n--;
}
cards[n + 1].setValue(val);

}

}

}

__________________________

CardSortingTest.java

public class CardSortingTest {

public static void main(String[] args) {

String[] cardsForPlayer1={"S4","D8","C4","D3","D5","DJ","S3","D4","DA","SJ","D7","H10","D6"};

Card[] cards=new Card[13];

for(int i=0;i<cardsForPlayer1.length;i++)

{

Card mcard=new Card(cardsForPlayer1[i]);

cards[i]=mcard;

}

int id=1;

Player player =new Player(id);

player.setCards(cards);

player.printCards();

player.sortCards();

player.printCards();

}

}

______________________

Output:

S4 D8 C4 D3 D5 DJ S3 D4 DA SJ D7 H10 D6
SJ S4 S3 H10 DJ DA D8 D7 D6 D5 D4 D3 C4

_____________Could you rate me well.Plz .Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote