Need help with this JAVA assignment, please look at the question carefully. Need
ID: 3859316 • Letter: N
Question
Need help with this JAVA assignment, please look at the question carefully. Need it ASAP, thank you.
You will write an implementation of a simple card game called War. Details of the game's rules can be found here: http://www.bicyclecards.com/how-to-play/war/ This game uses a "standard" deck of playing cards, and involves two players. Each player is dealt half of a randomly shuffled deck (so 26 cards each). During each turn, both players simultaneously flip the top card of their deck. The player who flips the highest value card wins the turn, and "captures" both cards by adding them to the bottom of their deck. If both players flip over cards with the same value, then a "war" begins: each player takes the next two cards from their deck, flipping over one and leaving the second face-down. The flipped cards are compared, and the highest value of these cards determines the winner, who now takes the "war pile" all six cards). If these are also the same value, then the war continues; both players continue drawing two cards from their deck and flipping only the first one to compare values. The ultimate winner takes all cards in the "war pile". After a war, play resumes as normal by flipping and comparing only one card each at a time. Your gameshouldthre class Card,Deck,and Demo. Your game should use three class: Card, Deck, and DemoExplanation / Answer
Answer:
import java.util.*;
public class Card
{
private String mySuit;
private int myValue;
public Card( String suit, int value )
{
mySuit = suit;
myValue = value;
}
public String name()
{
String[] cardNames =
{
"Deuce", "Three", "Four", "Five",
"Six", "Seven", "Eight", "Nine", "Ten",
"Jack", "Queen", "King", "Ace"
};
return cardNames[ myValue - 2 ] + " of " + mySuit;
}
}
}
class MainClass
{
public static void displayCards( ArrayList<Card> a )
{
int i;
System.out.println( "Size is " + a.size() );
for ( i = 0 ; i < a.size() ; i++ )
{
Card c = a.get( i );
System.out.println( "#" + (i+1) + ": " + c.name() );
}
}
public static ArrayList<Card> makeDeck()
{
ArrayList<Card> cards = new ArrayList<Card>();
String[] cardNames =
{
"Deuce", "Three", "Four", "Five",
"Six", "Seven", "Eight", "Nine", "Ten",
"Jack", "Queen", "King", "Ace"
};
String[] suits = { "spades", "hearts", "diamonds", "clubs" };
for (int a=0; a < suits.length; a++)
{
for (int b=0; b< 13 ; b++)
{
cards.add(new Card(suits[a],b));
}
}
return cards;
}
public static void main( String[] args )
{
System.out.println(makeDeck());
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.