title: Creating something that Checks if its a Royal Flush
body: <p>Im trying to check to see if a hand in poker is a Royal Flush. However, when I keep checking it, it comes up as Straight Flush and not Royal Flush. I have modified it slightly but am unable to check it because I forgot to send myself one of the main programs I needed for it. But the problem still holds.</p>
  
  <pre><code>private boolean isRoyalFlush(){//check if from 10-Ace and All of same suit---
    if(isFlush()==true){
        sortByValue();
        if((cards[0].rank==10)&amp;&amp;(cards[1].rank==11)&amp;&amp;(cards[2].rank==12)&amp;&amp;(cards[3].rank==13)&amp;&amp;(cards[4].rank==14)){
            return true;
        }
        else{
            return false;
        }
    }
    else{
        return false;
    }
  }
  </code></pre>
  
  <p>In theory the cards[i].rank gets the rank of the card, where 11==Jack, 12==Queen, etc. isFlush() checks to see if all of same suit. sortByValue(); sorts the cards into numerical value.</p>
  
  <p>Other Code:</p>
  
  <p>Card File</p>
  
  <pre><code>package playingcards;
  
  public class Card {
  
   public final static int CLUBS = 0, DIAMONDS = 1, HEARTS = 2, SPADES = 3;
   public final static int JACK = 11, QUEEN = 12, KING = 13, ACE = 14;
  
   public final int suit; // 0 .. 3
   public final int rank; // 0 .. 12
  
   private final static String[] suits = { "Clubs", "Diamonds", "Hearts",
     "Spades" };
   private final static String[] ranks = { "2", "3", "4", "5", "6", "7", "8",
     "9", "10", "Jack", "Queen", "King", "Ace" };
  </code></pre>
  
  <p>/**
    * Create a card with value v, as ordered first by suit (Clubs, Diamonds,
    * Hearts, Spades, in increasing order), the by rank (aces high). For
    * example, the value 1 corresponds to the 2 of Clubs, 12 to the Ace of
    * Clubs, and 13 to the 2 of Diamonds.
    * 
    * @param v
    *            a value between 1 and 52
    * @throws IllegalArgumentException
    *             if v less than 1 or greater than 52
    */</p>
  
  <pre><code> public Card(int v) {
    // PRE:
    if (!(1 &lt;= v &amp;&amp; v &lt;= 52)) {
     throw new IllegalArgumentException("Bad constructor arguments " + v);
    }
    suit = (v - 1) / 13;
    rank = (v - 1) % 13;
   }
  </code></pre>
  
  <p>/**
    * Create a card with rank r and suit s. Rank values are literal for number
    * ranks, 10 for Jacks, 14 for Aces, and so on. Suits are ordered from 0 to
    * 3, corresponding to Clubs, Diamonds, Hearts, and Spades. Note that this
    * class includes symbolic constants for all rank and suit values.
    * 
    * @param r
    *            the card's rank a value between 2 and Card.ACE (14)
    * @param s
    *            the suit, a value between Card.CLUBS (0) and Card.SPADES (3)
    * 
    * @throws IllegalArgumentException
    *             if r is not between 2 and 14 (inclusive) or if s is not
    *             between 0 and 3 (inclusive)
    */</p>
  
  <pre><code> public Card(int r, int s) {
    // PRE: (0 &lt;= s &lt;= 3) AND (2 &lt;= r &lt;= 14)
    if (!((0 &lt;= s &amp;&amp; s &lt;= 3) &amp;&amp; (2 &lt;= r &amp;&amp; r &lt;= 14))) {
     throw new IllegalArgumentException("Bad constructor arguments " + r
       + "," + s);
    }
    suit = s;
    rank = r - 2;
   }
  </code></pre>
  
  <p>/**
    * Returns a string representation of this card, including both its suit and
    * its value. Sample return values are: "Queen of Hearts", "10 of Diamonds",
    * "Ace of Spades"
    */</p>
  
  <pre><code>     public String toString() {
        return ranks[rank] + " of " + suits[suit];
       }
  
   // New things:
  </code></pre>
  
  <p>/**
    * Returns -1, 1, or 0, according to whether this Card is greater than, less
    * than or equal to its argument. The ordering is that of traditional draw
    * poker: by rank first (aces high), then by suit.
    * 
    * @throws NullPointerException
    *             if c is null
    */</p>
  
  <pre><code> public int compareTo(Card c) {
    if (c.rank &gt; this.rank || (c.rank == this.rank &amp;&amp; c.suit &gt; this.suit)) {
     return -1;
    } else if (this.rank &gt; c.rank
      || (this.rank == c.rank &amp;&amp; this.suit &gt; c.suit)) {
     return 1;
    } else {
     return 0;
    }
   }
  
   public boolean equals(Card c) {
    return this.compareTo(c) == 0;
   }
  
  } // Card
  </code></pre>