Question: a. You designed a Card class. The class holds fields that contain a Cards value and suit. Currently, the suit is represented by a single

a. You designed a Card class. The class holds fields that contain 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 setValue() method, besides setting the numeric value, also set the string rank value as follows.

Numeric Value String Value for Rank Ace 2 through 10 2 through 10 Jack 11 Queen 12 King 13

b. You created a War Card game that randomly selects two cards (one for the player and one for the computer) and declares a winner (or a tie). Modify the game to set each Card€™s suit as the appropriate string, then execute the game using the newly modified Card class. Figure 7-18 shows a typical execution. Recall that in this version of War, you assume that the Ace is the lowest-valued card. Save the game as War2.java.

My card is the King of Diamonds Your card is the 6 of Clubs I win

Numeric Value String Value for Rank Ace 2 through 10 2 through 10 Jack 11 Queen 12 King 13 My card is the King of Diamonds Your card is the 6 of Clubs I win

Step by Step Solution

3.50 Rating (160 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

a public class Card private String suit private int value private String rank public String getSuit ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Java Programming Questions!