Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Program (WAR CARD GAME) War is a card game for two players. A standard deck of 52 cards is dealt so that both players

Java Program (WAR CARD GAME)

War is a card game for two players.

A standard deck of 52 cards is dealt so that both players have 26 cards.

During each round of play (or "battle"), both players play a card from the top of their hand face up.

The player who plays the card of the higher rank wins both cards and places them at the bottom of his stack of cards.

If both cards played are of the same rank, then both players play three additional cards face down and then one more card face up (this is called a "war").

The player who wins the war by playing the higher card wins all ten cards.

If the ranks are still the same, additional wars are played until one player wins the turn.

If either player runs out of cards to play, he loses the game.

You will use only ArrayLists to store the cards in this program. This means cards cannot be stored in arrays.

Sample output might look like this:

player 1 plays Card is 9 of Clubs player 2 plays Card is Ace of Diamonds player 2 wins the round player 1 plays Card is 10 of Diamonds player 2 plays Card is Ace of Hearts player 2 wins the round player 1 plays Card is 7 of Clubs player 2 plays Card is 6 of Hearts player 1 wins the round player 1 plays Card is 9 of Hearts player 2 plays Card is 9 of Clubs war war card for player1 Card is xx war card for player2 Card is xx war card for player1 Card is xx war card for player2 Card is xx war card for player1 Card is xx war card for player2 Card is xx war card for player1 Card is 7 of Clubs war card for player2 Card is 10 of Diamonds player 2 wins the war round player 1 plays Card is 6 of Hearts player 2 plays Card is Ace of Hearts player 2 wins the round game over player 2 wins the game 

Think of a Card as an object with properties (rank, suit, etc.)

Think of a Deck of Cards as a Collection of Objects

Think of the remaining objects: Hand, Discard Pile, etc. as a collection of objects

You may find methods in the Collections class that will help with some of the functionality needed in this project.

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