Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / You will be designing a program that allows you to play the card games War at the terminal against the computer, at Antonella's Cyber Casino

You will be designing a program that allows you to play the card games War at the terminal against the computer, at Antonella's Cyber Casino

Computer Science

You will be designing a program that allows you to play the card games War at the terminal against the computer, at Antonella's Cyber Casino. To make designing the game easier, you will create two classes, which are specified here:
Card class - the class representing a single card in a deck. Every card has three properties. The first
is a "suit," which is either "Hearts", "Diamonds," "Spades", or "Clubs". A card also has a color,
where Hearts and Diamonds are red, and Spades and Clubs are black. Finally, each card has a value
from 1-13 (inclusive). Some values have special names: the 1 is an Ace, 11 is a Jack, 12 is a Queen,
and 13 is a King.
Your first job is to design a class for a card, with each of these properties. It should have these
methods:
1. public Card(int value, String suit) - initializes the Card and it's variables. For example,
Card(12, "Hearts") will create red 12 of hearts.
2. public int getValue( ) - returns value of the card
3. public String getColor( ) - returns color of the card
4. public String getSuit( ) - returns suit of the card
5. public String toString() - returns string representation of the card, E.G. "King of Hearts."
Or "7 of clubs"


DECK CLASS
In an entire deck, there are 52 cards, each of the 13 values for the four different suits. You should
implement a class to handle all of the logistics of the deck, so that as a user of the class, all you
have to do is pick cards from the deck, and then discard them once you're done with them. This
class has a bit more logic in it, so here's what you have to do.
1. public Deck()
This method will initialize the deck - creating an array of each of the 52 possible
cards. After generating them, you should also shuffle them in the array (shuffling
method is defined below). This method should also initialize a discard pile array,
which currently has nothing in it. You may want to initialize other variables too,
to assist with your other methods.
2. public void shuffle()
This method shuffles all of the items in the deck. You can be creative with your
shuffling algorithm, but I suggest you implement this one (the first algorithm under
"The Modern Algorithm"). This is in "pseudo code," which means it's not in a real
programming language, so it will be your job to convert this into real java code.
Make sure if there are some "null" elements in your deck, that you don't shuffle
them into the deck.
3. public Card drawNextCard()
This method will give you the next card in the deck. Initially, this will be the card
at index 0, then index 1, then index 2... up until index 51. After index 51,
drawNextCard should take all of the cards in the discard pile, put them in the deck
array, empty the discard pile, shuffle them, and then return the first one.
4. public void discard(Card c)
This method will add the card into the discard pile. Initially it will add the card to
the first index of the discard pile, then the second index, etc...

 

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE