Description

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. (When you learn more about string handling in the chapter "Characters, Strings, and the StringBuilder," you can modify the class to hold words for the suits, such as spades or hearts, as well as words for some of the valuesfor example, ace or king.) 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. Appendix D contains information about generating random numbers. To fully understand the process, you must learn more about Java classes and methods. However, for now, you can copy the following statements to 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); After reading the chapter "Making Decisions," 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.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.