Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java 'Array of references card game. In this project you will create a solution designed to play a simplified version of the card game WAR

Java 'Array of references card game. In this project you will create a solution designed to play a simplified version of the card game "WAR" . we will use simplified rules of the game. Create a deck of cards. Shuffle the deck . Deal the deck into two-faced piles of 26 cards each. Turn over the top card from each players pile and display the card using the toString() method. Whoever onws the higher of the two cards wins possesion of both the cards and places them in their "wiin" pile. If the two cards turn up with the same value( use the getValue() method. each player then puts an additional card into the center pile and turns over a second card. The owner of the higher of this newly turned over card wins all the cards in that play( the two original and the four additional). If tthis results in another tie, the same procedure is followed. Once the two original piles are depleted, count the number of the cards owned by each player. The player with the most number of cards wins the game. How to get Started Create a class called Card. The card has three fields; a value , a suit and a face. The card class has a constructor that takes three of the fields Write three get methods() to return the values of each of the fields. Write a toString method. Write a compareTo() method that uses the value of the card to determine the ordering. For values, a face of "two" has a value of 2. a face of "three" has a value of 3 ...... For this game Jack, Queen , and King are valued in ascending order and Ace has the highest value. Write a equals () method that returns true if argument Card has the same suit and the same face as the invoking card. Create a class called Deck. A deck has two fieds- an array of Card references and an index to hold the subscript of the top card. The deck class will have only one constructor, which will create the array. Try to think of a way to code this without writing 52 statements.( not required). The deck class also has a method getTopCard() which returns a reference to the Card that is at the top of the array. Write a method called shuffle () which shuffles the array of Cards. To shuffle, generate random numbers and use these to exchange array elements. Exchange 1000 times in this method. If you are unsure of how to generate random number after reading the Java API documentation on the Random class please look in your notes. Create the Driver class- call it Game This is where your game logic will go. As a hint, you will need to create an instance of the deck class and call its shuffle() method. Deal the cards from the Deck for each player(two more arrays) Draw the cards, show the card and determine who wins the two cards or if a war is needed Once a game is won, allow the user to decide if he/she wants to play another game. keep running a total of the number of games won by the two players. This is what i have so far

public class Card { private final static int SPADES = 0; private final static int HEARTS = 1; private final static int DIAMONDS = 2; private final static int CLUBS = 3; private final static int JOKER = 4; private final static int ACE = 1; private final static int JACK = 11; private final static int QUEEN = 12; // numerical values for their codes. private final static int KING = 13; private final int suit; private final int value; public Card() { suit = JOKER; value = 1; } public Card(int theValue, int theSuit) { if (theSuit != SPADES && theSuit != HEARTS && theSuit != DIAMONDS && theSuit != CLUBS && theSuit != JOKER) throw new IllegalArgumentException("Illegal playing card suit"); if (theSuit != JOKER && (theValue < 1 || theValue > 13)) throw new IllegalArgumentException("Illegal playing card value"); value = theValue; suit = theSuit; } public int getSuit() { return suit; } public int getValue() { return value; } public String getSuitAsString() { switch ( suit ) { case SPADES: return "Spades"; case HEARTS: return "Hearts"; case DIAMONDS: return "Diamonds"; case CLUBS: return "Clubs"; default: return "Joker"; } } public String getValueAsString() { if (suit == JOKER) return "" + value; else { switch ( value ) { case 1: return "Ace"; case 2: return "2"; case 3: return "3"; case 4: return "4"; case 5: return "5"; case 6: return "6"; case 7: return "7"; case 8: return "8"; case 9: return "9"; case 10: return "10"; case 11: return "Jack"; case 12: return "Queen"; default: return "King"; } } } public String toString() { if (suit == JOKER) { if (value == 1) return "Joker"; else return "Joker #" + value; } else return getValueAsString() + " of " + getSuitAsString(); } } // end class Card

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_2

Step: 3

blur-text-image_3

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

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions

Question

Identify the cause of a performance problem. page 363

Answered: 1 week ago

Question

3. The group answers the questions.

Answered: 1 week ago