Answer programming logic and design 8e game zone 1 a

This preview shows page 13 - 17 out of 17 pages.

We have textbook solutions for you!
The document you are viewing contains questions related to this textbook.
Java Programming
The document you are viewing contains questions related to this textbook.
Chapter 1 / Exercise 5
Java Programming
Farrell
Expert Verified
Answer:
We have textbook solutions for you!
The document you are viewing contains questions related to this textbook.
Java Programming
The document you are viewing contains questions related to this textbook.
Chapter 1 / Exercise 5
Java Programming
Farrell
Expert Verified
Programming Logic and Design, 8eSolutions 10-14Game Zone1.a. 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 string data field to hold a suit (spades, hearts, diamonds, or clubs) and a numeric data field for a value from 1 to 13. Include get and set methods for each field. Write an application that randomly selects two playing cards and displays their values.
Programming Logic and Design, 8e
b. Using two Card objects, design an application that plays a simple version of the card game War. Deal two Cards—one for the computer and one for the player. 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 that 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 Queen of Spades.
Programming Logic and Design, 8eSolutions 10-16playerCard.getValue() = computerCard.getValue()computerCard.setValue(random(VALUE_LIMIT))computerCard.setSuit(random(SUIT_LIMIT))endwhileif playerCard.getValue() > computerCard.getValue() thenoutput “You win!”elseif playerCard.getValue() <computerCard.getValue() thenoutput “Computer wins”elseoutput “Tie!”endifendifstopUp for Discussion

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture