ผลต่างระหว่างรุ่นของ "01219343/unit/poker"
ไปยังการนำทาง
ไปยังการค้นหา
Jittat (คุย | มีส่วนร่วม) (→Card) |
Jittat (คุย | มีส่วนร่วม) (→Card) |
||
แถว 11: | แถว 11: | ||
Card card = new Card("10","S"); | Card card = new Card("10","S"); | ||
− | * Getters: <code>getRank</code> and <code>getSuit</code> | + | * Getters: <code>getRank</code> and <code>getSuit</code>. |
− | * <code>hasSameRank</code> | + | * <code>hasSameRank(Card c)</code> that returns true when <code>c</code> has the same rank. |
− | * <code>hasSameSuit</code> | + | * <code>hasSameSuit(Card c)</code> that returns true when <code>c</code> has the same suit. |
* The class should implement interface <code>Comparable<Card></code> so that we can easily sort the cards. Add that interface to the class and implement a public method <code>int compareTo(Card c)</code>. | * The class should implement interface <code>Comparable<Card></code> so that we can easily sort the cards. Add that interface to the class and implement a public method <code>int compareTo(Card c)</code>. | ||
+ | |||
+ | Make sure you test these method thoroughly. | ||
== Hand == | == Hand == | ||
Use [https://en.wikipedia.org/wiki/List_of_poker_hands|this reference of poker hands] from wikipedia. | Use [https://en.wikipedia.org/wiki/List_of_poker_hands|this reference of poker hands] from wikipedia. |
รุ่นแก้ไขเมื่อ 16:22, 24 มกราคม 2556
Follow the TDD steps to write these classes.
Card
A card has a rank (A,1,...,9,10,J,Q,K) and a suit (S,H,D,C) (see suit).
Implement class Card
that supports the following methods:
- Construction with rank and suit as strings. (This might not be an efficient way to represent ranks and suits, but it simplifies the exercise.) For example:
Card card = new Card("10","S");
- Getters:
getRank
andgetSuit
. hasSameRank(Card c)
that returns true whenc
has the same rank.hasSameSuit(Card c)
that returns true whenc
has the same suit.- The class should implement interface
Comparable<Card>
so that we can easily sort the cards. Add that interface to the class and implement a public methodint compareTo(Card c)
.
Make sure you test these method thoroughly.
Hand
Use reference of poker hands from wikipedia.