Java Program (WAR CARD GAME) War is a card game for two players. A standard deck
ID: 3887808 • Letter: J
Question
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:
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.
Explanation / Answer
public class Card { private int cardNum; final static String[] suits = {"Spades", "Hearts", "Diamonds", "Clubs"}; final static String[] ranks = {"2", "3","4","5","6","7","8", "9","10", "Jack", "Queen", "King", "Ace"}; Card (int theCard) { setCardNum (theCard); } public void setCardNum (int theCard) { cardNum = (theCard >= 0 && theCardRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.