ผลต่างระหว่างรุ่นของ "01219343/unit/poker"
ไปยังการนำทาง
ไปยังการค้นหา
Jittat (คุย | มีส่วนร่วม) |
Jittat (คุย | มีส่วนร่วม) |
||
| แถว 19: | แถว 19: | ||
Make sure you test these method thoroughly. When fixing a broken tast, write the simplest possible code that make the test passes. | Make sure you test these method thoroughly. When fixing a broken tast, write the simplest possible code that make the test passes. | ||
| + | |||
| + | Given a list of <code>Card</code>s, we want to use <code>Collections.sort</code> to sort the list. Make sure you have a test case that tests this requirement. | ||
| + | |||
| + | '''Notes:''' To create a list of Cards, you can try, e.g., | ||
| + | |||
| + | List<Card> cards = Arrays.asList(new Card("10","S"), new Card("9", "D"), new Card("A","C")); | ||
== 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:43, 24 มกราคม 2556
- This exercise is part of 01219343-55.
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:
getRankandgetSuit. hasSameRank(Card c)that returns true whenchas the same rank.hasSameSuit(Card c)that returns true whenchas 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. When fixing a broken tast, write the simplest possible code that make the test passes.
Given a list of Cards, we want to use Collections.sort to sort the list. Make sure you have a test case that tests this requirement.
Notes: To create a list of Cards, you can try, e.g.,
List<Card> cards = Arrays.asList(new Card("10","S"), new Card("9", "D"), new Card("A","C"));
Hand
Use reference of poker hands from wikipedia.