title: How to Make Suit Of Card (Order) Have an effect on the resultant drawn card
body: <p>My goal is to modify the program given (The 4 classes) By allowing the suit to take an affect on the result of the program. In general the user is given a card than the user is proceeded to guess whether the next card will have a higher numerical value. However, I'm not so sure on how to modify it to take into account the suit order. PLEASE NOTE THAT I NEEDED TO PUT THIS MUCH CODE, because the resultant input from people helping me would need to be incorporated into more than just one class of the programm. As this is a beginners Java program/</p>
  
  <p>The suit order meaning if Someone receives a 7 of hearts, and the next card is a 7 of clubs, the result should not be a tie, since Hearts has a greater suit value than clubs.</p>
  
  <p>As the suits rank as : SPADES > DIAMONDS > HEARTS > CLUBS</p>
  
  <p>In the Highlow class, there is a line that reads : </p>
  
  <pre><code>if(nextCard.getValue() == currentCard.getValue()) {
  </code></pre>
  
  <p>Which indicitates identical values, this needs to be changed however.
  I have tried, compensating to learn the compareto() method, however, after hours of research I realized that it would be too complicated for me to comprehend into my code, and quite frankly even understand it. Furthermore, I have made an attempt at noting how the cases for the suits are simply used as strings, and thought that maybe they could be arranged by sum listing method, then further checked and printed. However that thought came to no avail as I felt as if I was over thinking the entire point of this exercise. The classes are below, any input would much be appreciated. </p>
  
  <pre><code>    public class Card {
  
    public final static int SPADES = 0;   // Codes for the 4 suits, plus Joker.
    public final static int HEARTS = 1;
    public final static int DIAMONDS = 2;
    public final static int CLUBS = 3;
    public final static int JOKER = 4;
  
    public final static int ACE = 1;      // Codes for the non-numeric cards.
    public final static int JACK = 11;    //   Cards 2 through 10 have their 
    public final static int QUEEN = 12;   //   numerical values for their codes.
    public final static int KING = 13;
  
  
    private final int suit; 
  
    private final int value;
    public static void main (String [] args){
    }
    public Card() {
      suit = JOKER;
      value = 1;
    }
  
    public Card(int theValue, int theSuit) {
      if (theSuit != SPADES &amp;&amp; theSuit != HEARTS &amp;&amp; theSuit != DIAMONDS &amp;&amp; 
          theSuit != CLUBS &amp;&amp; theSuit != JOKER)
        throw new IllegalArgumentException("Illegal playing card suit");
      if (theSuit != JOKER &amp;&amp; (theValue &lt; 1 || theValue &gt; 13))
        throw new IllegalArgumentException("Illegal playing card value");
      value = theValue;
      suit = theSuit;
    }
  
    public int getSuit() {
      return suit;
    }
  
    public int getValue() {
      return value;
    }
  
    public String getSuitAsString() {
      switch ( suit ) {
        case SPADES:   return "Spades";
        case HEARTS:   return "Hearts";
        case DIAMONDS: return "Diamonds";
        case CLUBS:    return "Clubs";
        default:       return "Joker";
      }
    }
  
    public String getValueAsString() {
      if (suit == JOKER)
        return "" + value;
      else {
        switch ( value ) {
          case 1:   return "Ace";
          case 2:   return "2";
          case 3:   return "3";
          case 4:   return "4";
          case 5:   return "5";
          case 6:   return "6";
          case 7:   return "7";
          case 8:   return "8";
          case 9:   return "9";
          case 10:  return "10";
          case 11:  return "Jack";
          case 12:  return "Queen";
          default:  return "King";
        }
      }
    }   
    public String toString() {
      if (suit == JOKER) {
        if (value == 1)
          return "Joker";
        else
          return "Joker #" + value;
      }
      else {
  
          return getValueAsString() + " of " + getSuitAsString() ;
        }
      }
  
  }
  </code></pre>
  
  <p>Deck CLass: </p>
  
  <pre><code>public class Deck {
     private Card[] deck;
     private int cardsUsed;
  
     public Deck() {
        this(false);  
     }
  
     public Deck(boolean includeJokers) {
        if (includeJokers)
           deck = new Card[54];
        else
           deck = new Card[52];
        int cardCt = 0; // How many cards have been created so far.
        for ( int suit = 0; suit &lt;= 3; suit++ ) {
           for ( int value = 1; value &lt;= 13; value++ ) {
              deck[cardCt] = new Card(value,suit);
              cardCt++;
           }
        }
        if (includeJokers) {
           deck[52] = new Card(1,Card.JOKER);
           deck[53] = new Card(2,Card.JOKER);
        }
        cardsUsed = 0;
     }
  
     public void shuffle() {
        for ( int i = deck.length-1; i &gt; 0; i-- ) {
           int rand = (int)(Math.random()*(i+1));
           Card temp = deck[i];
           deck[i] = deck[rand];
           deck[rand] = temp;
        }
        cardsUsed = 0;
     }
  
     public int cardsLeft() {
        return deck.length - cardsUsed;
     }
  
     public Card dealCard() {
        if (cardsUsed == deck.length)
           throw new IllegalStateException("No cards are left in the deck.");
        cardsUsed++;
        return deck[cardsUsed - 1];
     }
     public boolean hasJokers() {
        return (deck.length == 54);
     }
  } 
  </code></pre>
  
  <p>Hand Class</p>
  
  <pre><code>import java.util.ArrayList;
  
  public class Hand {
  
     private ArrayList hand;   
  
     public Hand() {
        hand = new ArrayList();
     }
  
     public void clear() {
        hand.clear();
     }
  
     public void addCard(Card c) {
        if (c == null)
           throw new NullPointerException("Can't add a null card to a hand.");
        hand.add(c);
     }
  
     public void removeCard(Card c) {
        hand.remove(c);
     }
  
     public void removeCard(int position) {
        if (position &lt; 0 || position &gt;= hand.size())
           throw new IllegalArgumentException("Position does not exist in hand: "
                 + position);
        hand.remove(position);
     }
  
     public int getCardCount() {
        return hand.size();
     }
  
     public Card getCard(int position) {
        if (position &lt; 0 || position &gt;= hand.size())
           throw new IllegalArgumentException("Position does not exist in hand: "
                 + position);
         return (Card)hand.get(position);
     }
  
     public void sortBySuit() {
        ArrayList newHand = new ArrayList();
        while (hand.size() &gt; 0) {
           int pos = 0;  // Position of minimal card.
           Card c = (Card)hand.get(0);  // Minimal card.
           for (int i = 1; i &lt; hand.size(); i++) {
              Card c1 = (Card)hand.get(i);
              if ( c1.getSuit() &lt; c.getSuit() ||
                      (c1.getSuit() == c.getSuit() &amp;&amp; c1.getValue() &lt; c.getValue()) ) {
                  pos = i;
                  c = c1;
              }
           }
           hand.remove(pos);
           newHand.add(c);
        }
        hand = newHand;
     }
  
     public void sortByValue() {
        ArrayList newHand = new ArrayList();
        while (hand.size() &gt; 0) {
           int pos = 0;  // Position of minimal card.
           Card c = (Card)hand.get(0);  // Minimal card.
           for (int i = 1; i &lt; hand.size(); i++) {
              Card c1 = (Card)hand.get(i);
              if ( c1.getValue() &lt; c.getValue() ||
                      (c1.getValue() == c.getValue() &amp;&amp; c1.getSuit() &lt; c.getSuit()) ) {
                  pos = i;
                  c = c1;
              }
           }
           hand.remove(pos);
           newHand.add(c);
        }
        hand = newHand;
     }
  }
  </code></pre>
  
  <p>MAIN PROGRAM CLASS </p>
  
  <pre><code>import java.io.*;
  
  public class HighLow {
  
    public static void main(String[] args) {
  
      BufferedReader myInput = new BufferedReader (new InputStreamReader (System.in));  // allow input
  
      System.out.println("This program lets you play the simple card game,");
      System.out.println("HighLow.  A card is dealt from a deck of cards.");
      System.out.println("You have to predict whether the next card will be");
      System.out.println("higher or lower.  Your score in the game is the");
      System.out.println("number of correct predictions you make before");
      System.out.println("you guess wrong.");
      System.out.println();
  
      int gamesPlayed = 0;     // Number of games user has played.
      int sumOfScores = 0;     // The sum of all the scores from 
      //      all the games played.
      double averageScore;     // Average score, computed by dividing
      //      sumOfScores by gamesPlayed.
      boolean playAgain;       // Record user's response when user is 
      //   asked whether he wants to play 
      //   another game.
      do {
        int scoreThisGame;        // Score for one game.
        scoreThisGame = play();   // Play the game and get the score.
        sumOfScores += scoreThisGame;
        gamesPlayed++;
        System.out.println("Play again? ");
        playAgain = TextIO.getlnBoolean();
      } while (playAgain);
  
      averageScore = ((double)sumOfScores) / gamesPlayed;
  
      System.out.println();
      System.out.println("You played " + gamesPlayed + " games.");
      System.out.printf("Your average score was %1.3f.\n", averageScore);
  
    }  // end main()
  
    private static int play() {
  
      Deck deck = new Deck();  // Get a new deck of cards, and 
      Card currentCard;  // The current card, which the user sees.
      Card nextCard;   // The next card in the deck.  The user tries
      int correctGuesses ;  // The number of correct predictions the
      char guess;   // The user's guess.  'H' if the user predicts that
      deck.shuffle();  // Shuffle the deck into a random order before
      correctGuesses = 0;
      currentCard = deck.dealCard();
      System.out.println("The first card is the " + currentCard);
      while (true) {  // Loop ends when user's prediction is wrong.
  
        /* Get the user's prediction, 'H' or 'L' (or 'h' or 'l'). */
  
        TextIO.put("Will the next card be higher (H) or lower (L)?  ");
        do {
          guess = TextIO.getlnChar();
          guess = Character.toUpperCase(guess);
          if (guess != 'H' &amp;&amp; guess != 'L') 
            System.out.println("Please respond with H or L:  ");
        } while (guess != 'H' &amp;&amp; guess != 'L');
  
        nextCard = deck.dealCard();
        System.out.println("The next card is " + nextCard);
  
        if(nextCard.getValue() == currentCard.getValue()) {
  
          System.out.println("The value is the same as the previous card.");
          System.out.println("You lose on ties.  Sorry!");
          break;  // End the game.
        }
        else if (nextCard.getValue() &gt; currentCard.getValue()) {
          if (guess == 'H') {
            System.out.println("Your prediction was correct.");
            correctGuesses++;
          }
          else {
            System.out.println("Your prediction was incorrect.");
            break;  // End the game.
          }
        }
        else {  // nextCard is lower
          if (guess == 'L') {
            System.out.println("Your prediction was correct.");
            correctGuesses++;
          }
          else {
            System.out.println("Your prediction was incorrect.");
            break;  // End the game.
          }
        }
        currentCard = nextCard;
        System.out.println();
        System.out.println("The card is " + currentCard);
  
      } // end of while loop
  
      System.out.println();
      System.out.println("The game is over.");
      System.out.println("You made " + correctGuesses 
                           + " correct predictions.");
      System.out.println();    
      return correctGuesses;
    }  
  } 
  </code></pre>