Question: Given these three classes of code: Class 1: Card /** * A class of playing cards. * * @author Erin Encinias */ public class Card
Given these three classes of code:
Class 1: Card
/**
* A class of playing cards.
*
* @author Erin Encinias
*/
public class Card
{
private static final String[] SUIT_DESCRIPTION =
{"Spades", "Hearts", "Diamonds", "Clubs"};
private static final String[] FACE_VALUE_DESCRIPTION =
{ "Ace", "2", "3", "4", "5", "6", "7", "8", "9",
"10", "Jack", "Queen", "King"};
private int suit;
private int faceValue;
/**
* Create a new card with a given suit and value
*
* @param v the face value of the card (0 - 12)
* @param s the suit of the card (0 - 3)
*/
public Card(int v, int s)
{
faceValue = v;
suit = s;
}
/**
* @return the suit of this card
*/
public int getValue()
{
return faceValue;
}
/**
* @see java.lang.Object#toString()
*/
public String toString()
{
return FACE_VALUE_DESCRIPTION[faceValue] + " of " + SUIT_DESCRIPTION[suit];
}
}
Class 2: Cardrunner
/**
* Just a main method to let us play with Decks
* and Cards
*/
public class CardRunner
{
/**
* Variables of the type Card are declared and cards are created as well
* The deck of the cards is created and shuffled
* @param args
*/
public static void main(String[] args)
{
Card c1 = new Card (0,0);
System.out.println(c1);
Card c2 = new Card(12,3);
System.out.println(c2);
System.out.println();
Deck d = new Deck();
d.shuffle();
System.out.println(d);
}
}
Class 3: Deck
/**
* A standard deck of 52 cards in four suits.
*/
public class Deck
{
private static final int NUMBER_OF_SUITS = 4;
private static final int NUMBER_OF_CARDS = 52;
Card[] cards;
/**
* Create the deck by filling it with the appropriate cards
*/
public Deck()
{
cards = new Card[NUMBER_OF_CARDS];
int position = 0;
for (int suit = 0; suit < NUMBER_OF_SUITS; suit++)
{
for (int faceValue = 0;
faceValue < NUMBER_OF_CARDS/NUMBER_OF_SUITS;
faceValue++)
{
cards[position] =
new Card(faceValue, suit);
position++;
}
}
}
/**
* @see java.lang.Object#toString()
*/
public String toString()
{
String s = new String();
for (int i = 0; i < cards.length; i++)
{
s = s + cards[i] + " ";
}
return s;
}
/**
* randomly shuffle the cards using the Fisher-Yates shuffle
*/
public void shuffle()
{
for (int i = 0; i < NUMBER_OF_CARDS; i++)
{
int swapPosition = (int) (Math.random() * (NUMBER_OF_CARDS - i) + i);
Card temp = cards[i];
cards[i] = cards[swapPosition];
cards[swapPosition] = temp;
}
}
}
Question:
What was the original order in which the Deck was created?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
