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

he class holds fields that con tain a. In Chapter 3, you designed a Card class.

ID: 3709434 • Letter: H

Question

he class holds fields that con tain a. In Chapter 3, you designed a Card class. T a Card's value and suit. Currently, the suit is represented by a single character (s, h, d, or c). Modify the class so that the suit is a string ('Spades", "Hearts "Diamonds", or "Clubs"). Also, add a new field to the class to hold the string representation of a Card's rank based on its value. Within the Card class setvalueO method, besides setting the numeric value, also set the string rank value as follows. String value for rank Ace "2" through "10 "Jack" "Queen" uKing Numeric value 2 through 10 12 13

Explanation / Answer

Hi, I have implemented Question a. The card class is updated and I have set a new method setValue(int value) which sets the numeric value and also sets a String value for the Cards like Ace Jack King Queen as given in the table.

For part b I think you already have a War.java class. You just need to update set value method and you are good to go. The question in part b just needs the field rank to be implemented. No new method id required. Just add setValue() in War.java class. I hope you have understood this. Kindly see the Card.java class below:

*********************************************************************************************************************

Card.java

public class Card {

private String suit;

private int value;

private String rank;

public Card() {

}

public Card(String suit, int value) {

setSuit(suit);

setValue(value);

}

public String getSuit() {

return suit;

}

public void setSuit(String suit) {

this.suit = suit;

}

public int getValue() {

return value;

}

public void setValue(int value) {

this.value = value;

if(value == 1) {

this.rank = "Ace";

}

else if(value>=2 && value<=10) {

this.rank = "2 through 10";

}

else if(value == 11) {

this.rank = "Jack";

}

else if(value == 12) {

this.rank = "Queen";

}

else if(value == 13) {

this.rank = "King";

}

}

@Override

public String toString() {

return "Card [suit=" + suit + ", value=" + value + ", rank=" + rank + "]";

}

public static void main(String[] args) {

Card card1 = new Card("Spades",10);

Card card2 = new Card("Hearts",1);

Card card3 = new Card("Diamonds",6);

Card card4 = new Card("Clubs",13);

System.out.println(card1);

System.out.println(card2);

System.out.println(card3);

System.out.println(card4);

}

}

Test Outputs:

Card [suit=Spades, value=10, rank=2 through 10]
Card [suit=Hearts, value=1, rank=Ace]
Card [suit=Diamonds, value=6, rank=2 through 10]
Card [suit=Clubs, value=13, rank=King]

**************************************************************************************************************************

P.S

You can remove toString() and main() It is just for testing that the code works okay and the implementation is correct.

Update War.java to create war2.java. If you have any queries, Kindly comment. I'll reply and help you out. All the best. Please rate the answer. All the best.