The final objective of this project is to create a any multi
The final objective of this project is to create a any multi-player card game, but you will create your classes in the order given, as specified.
Classes required : 1. CARD.JAVA
2. PILE OF CARDS.JAVA
3. DECK AND HANDS.JAVA
4. PLAYER.JAVA
5. GAME.JAVA
Make any multiplayer card game BUT YOU HAVE TO USE and CODE all the above classes.
Solution
Card Class:
 class Card implements PileofCard {
 public int color;
 public int value;
 public String ImageName;
 }
 Pile of card Class which is interfaces:
 interface PileofCard {
 // interface fields are always public static final!
 int HEARTS 1;
 int DIAMOND 2;
 int SPADE 3;
 int CLUBS 4;
 int JACK 11;
 int QUEEN 12;
 int KING 13;
 int ACE_LOW 1;
 int ACE_HIGH 14;
 }
 Deck And hands class:
 public void shuffle () {
 // Always zero the deck vector and initialize it
 from scratch.
 deck.removeAllElements ();
 20
 // Then insert the 52 cards. One color at a time
 for (int i ACE_LOW; i < ACE_HIGH; i++) {
 Card aCard new Card ();
 aCard.color HEARTS;
 aCard.value i;
 deck.addElement (aCard);
 }
 // Do the same for CLUBS, DIAMONDS and SPADES.
 }
 public Card draw () {
 Card aCard null;
 int position (int) (Math.random () * (deck.size =
 ()));
 try {
 aCard (Card) deck.elementAt (position);
 }
 catch (ArrayIndexOutOfBoundsException e) {
 e.printStackTrace ();
 }
 deck.removeElementAt (position);
 return aCard;
 }
 public void dump () {
 Enumeration enum deck.elements ();
 while (enum.hasMoreElements ()) {
 Card card (Card) enum.nextElement ();
 RuleSet.printValue (card);
 }
 }
 public void dump () {
 Enumeration enum deck.elements ();
 while (enum.hasMoreElements ()) {
 Card card (Card) enum.nextElement ();
 RuleSet.printValue (card);
 }
 }
 public void take (Card theCard){
 cardHand.addElement (theCard);
 }
 public Card show (int position) {
 Card aCard null;
 try {
 aCard (Card) cardHand.elementAt (position);
 }
 catch (ArrayIndexOutOfBoundsException e){
 e.printStackTrace ();
 }
 return aCard;
 }
 20
 public Card draw (int position) {
 Card aCard show (position);
 cardHand.removeElementAt (position);
 return aCard;
 }
 public int NCards (int value) {
 int n 0;
 Enumeration enum cardHand.elements ();
 while (enum.hasMoreElements ()) {
 tempCard (Card) enum.nextElement (); // =
 tempCard defined
 if (tempCard.value= value)
 n++;
 }
 return n;
 }
 Player Class:
 public int higher (Card one, Card two) {
 int whichone 0;
 if (one.value= ACE_LOW)
 one.value ACE_HIGH;
 if (two.value= ACE_LOW)
 two.value ACE_HIGH;
 // In this rule set the highest value wins, we don\'t
 take into
 // account the color.
 if (one.value > two.value)
 whichone 1;
 if (one.value < two.value)
 whichone 2;
 if (one.value= two.value)
 whichone 0;
 // Normalize the ACE values, so what was passed in has
 the same values.
 if (one.value= ACE_HIGH)
 one.value ACE_LOW;
 if (two.value= ACE_HIGH)
 two.value ACE_LOW;
 return whichone;
 }
Game class:
 myCardDeck new CardDeck ();
 myRules new RuleSet ();
 handA new Hand ();
 handB new Hand ();
 DebugClass.DebugStr (\"Draw five cards each to hand A
 and hand B\");
 for (int i 0; i < NCARDS; i++) {
 handA.take (myCardDeck.draw ());
 handB.take (myCardDeck.draw ());
 }
 // Test programs, disable by either commenting out or
 using DEBUG flags.
 testHandValues ();
 testCardDeckOperations();
 testCardValues();
 testHighestCardValues();
 test21();
 DebugClass.DebugStr (\"Compare the second card in
 hand A and Hand B\");
 int winner myRules.higher (handA.show (1), =
 handB.show (1));
 if (winner= 1)
 o.println (\"Hand A had the highest card.\");
 else if (winner= 2)
 o.println (\"Hand B had the highest card.\");
 else
 o.println (\"It was a draw.\");
 int result myTwentyOneGame.isTwentyOne (handC);
 if (result= 21)
 o.println (\"We got Twenty-One!\");
 else if (result > 21)
 o.println (\"We lost \" + result);
 else {
 o.println (\"We take another card\");
 // ...
 }
For Debugging code is as follows..
 interface DebugConstants {
 boolean DEBUG true; // turns on and off =
 information message
 boolean DEBUG1 DEBUG;
 boolean DEBUG2 true; // enables/disables minor =
 dump information
 boolean DEBUG3 false; // enables/disables a lot =
 of dump information
 }
 class DebugClass implements DebugConstants {
 static final PrintStream o System.out;
 static void Assert (boolean b){
 if (!b) {
 new Throwable ().printStackTrace ();
 }
 }
 static void DebugStr (String string) {
 if (DEBUG)
 System.out.println (string);
 }




