b Using two Card objects design an application that plays a simple version of

B using two card objects design an application that

This preview shows page 29 - 31 out of 31 pages.

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, 8e Solutions 10-30 computerCard.setValue(random(VALUE_LIMIT)) computerCard.setSuit(random(SUIT_LIMIT)) endwhile if playerCard.getValue() > computerCard.getValue() then output “You win!” else if playerCard.getValue() < computerCard.getValue() then output “Computer wins” else output “Tie!” endif endif stop Up for Discussion 1.In this chapter, you learned that instance data and methods belong to objects, but that static data and methods belong to a class as a whole. Consider the real-life class named StateInTheUnitedStates. Name some real-life attributes of this class that are static attributes and instance attributes. Create another example of a real-life class and discuss what its static and instance members might be.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture