Question: Design a Card class that contains a character data field to hold a suit (s for spades, h for hearts, d for diamonds, or c

Design a Card class that contains a character data field to hold a suit (s for spades, h for hearts, d for diamonds, or c for clubs) and an integer data field for a value from 1 to 13. Include a setValue() method that does not allow a Card’s value to be less than 1 or higher than 13. If the argument to setValue() is out of range, assign 1 to the Card’s value. Save the file as Card.java. Play a very simple version of the card game War. Deal two Cards—one for the computer and one for the player—and set their suits and values randomly. Determine the higher card, then display a message indicating whether the cards are equal, the computer won, or the player won. (Playing cards are considered equal when they have the same value, no matter what their suit is.) For this game, assume the Ace (value 1) is low. Make sure that the two Cards dealt are not the same Card. For example, a deck cannot contain more than one Card representing the 2 of Spades. If two Cards are created to have the same values, change the suit for one of them. Save the application as War.java.

Step by Step Solution

3.50 Rating (153 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

public class Card final int LOW 1 final int HIGH 13 private char suit private i... 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!