Playing cards are used in many computer games, including versions of such classics as solitaire, hearts, and

Question:

Playing cards are used in many computer games, including versions of such classics as solitaire, hearts, and poker. 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 get and set methods for each field. Save the class as Card.java. Write an application that randomly selects two playing cards and displays their values. Simply assign a suit to each of the cards, but generate a random number for each card’s value. The following statements generate a random number between 1 and 13 and assign it to a variable:

final int CARDS_IN_SUIT = 13;
myValue = ((int)(Math.random() * 100) % CARDS_IN_SUIT + 1);

Later in this course, you will be able to have the game determine the higher card. For now, just observe how the card values change as you execute the program multiple times. Save the application as PickTwoCards.java.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  answer-question

Java Programming

ISBN: 9780357673423

10th Edition

Authors: Joyce Farrell

Question Posted: