Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 1: In the last assignment, you created a card class. Modify the card class so the setValue() method does not allow a cards value

Part 1: In the last assignment, you created a card class. Modify the card class so the setValue() method does not allow a cards value to be less than 1 or higher than 13. If the argument to setValue() is out of range, assign 1 to the cards value. You also created a PickTwoCards application that randomly selects two playing cards and displays their values. In that application, all card objects were arbitrarily assigned a suit represented by a single character, but they could have different values, and the player observed which of two card objects had the higher value. Now, modify the application so the suit and the value both are chosen randomly. Using two card objects play a very simple version of the card game War. Deal two cards one for the computer and one for the player and 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 the suit is). For this game, assume 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 card representing the 2 of spades. If two cards are chosen to have the same value, change the suit for one of them. Save the application as War.java

PART 2

Now modify the game using the newly modified card class so that when a tie is declared, that each player puts down 10 cards each and compares the 11th card to see if there is a clear winner. If there is a tie, repeat the process until there is a clear winner. The table below shows four typical executions. Recall that in this version of War, you assume that the ace is the lowest-valued card. Save the game as War2.java. So I expect a Card.java, War.java and War2.java file; Each working off the other. No need to reinvent the wheel! Lastly I expect, when WAR is called, to see all ten cards displayed.

card.java file

public class Card { private char suit; private int value; public Card() { suit= 's'; suit= 'h'; suit= 'd'; suit= 'c'; value=1; value=2; value=3; value=4; value=5; value=6; value=7; value=8; value=9; value=10; value=11; value=12; value=13; } public Card ( char suit, int value) { this.suit=suit; this.value=value; } public void setSuit(char suit) { this.suit=suit; } public char getSuit(char suit) { return suit; } public void setvalue (int value) { this.value=value; } public int getValue() { return value; } public String toString() { return value +" of " +suit; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server Query Performance Tuning

Authors: Sajal Dam, Grant Fritchey

4th Edition

1430267429, 9781430267423

More Books

Students also viewed these Databases questions