Write a program in Java to play the card game War. You may only use ArrayLists t
ID: 3886917 • Letter: W
Question
Write a program in Java to play the card game War. You may only use ArrayLists to store the cards in this program. A standard deck of 52 cards is dealt so that both players have 26 cards. During each play, both players get a card from the top of their hand face up.
Whoever 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.
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.
Explanation / Answer
import java.util.*;
import java.util.ArrayList;
public class cardWar{
Deck.add( 2);
Deck.add(3);
Deck.add(4);
Deck.add(5);
Deck.add(6);
Deck.add(7);
Deck.add(8);
Deck.add(9);
Deck.add(10);
Deck.add(11);
Deck.add(12);
Deck.add(13);
Deck.add(14);
Deck.add(2);
Deck.add(3);
Deck.add(4);
Deck.add(5);
Deck.add(6);
Deck.add(7);
Deck.add(8);
Deck.add(9);
Deck.add(10);
Deck.add(11);
Deck.add(12);
Deck.add(13);
Deck.add(14);
Deck.add( 2);
Deck.add(3);
Deck.add(4);
Deck.add(5);
Deck.add(6);
Deck.add(7);
Deck.add(8);
Deck.add(9);
Deck.add(10);
Deck.add(11);
Deck.add(12);
Deck.add(13);
Deck.add(14);
Deck.add(2);
Deck.add(3);
Deck.add(4);
Deck.add(5);
Deck.add(6);
Deck.add(7);
Deck.add(8);
Deck.add(9);
Deck.add(10);
Deck.add(11);
Deck.add(12);
Deck.add(13);
Deck.add(14);
Collections.shuffle(Deck);
int size=Deck.size();
int size1;
size1=size/2 +1;
faceofflist.remove(get(l));
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.