97%(230)222 out of 230 people found this document helpful
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, 8eSolutions 10-30computerCard.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 Discussion1.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.