package assignment.pk02playingcard; import java.util.List; import java.util.Arrays; /* * we'll play in VietNamese rule: * SPADE < CLUB < DIAMOND < HEART * 2 < 3 < 4 < ... < 10 < J < Q < K < A */ public class Card { private String[] rankArray = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A" }; private String[] suitArray = { "SPADE", "CLUB", "DIAMOND", "HEART" }; private ListrankList = Arrays.asList(rankArray); private List suitList = Arrays.asList(suitArray); /* * trong bảng mã Unicode * 9824 9829 9830 9827 * ♠ ♥ ♦ ♣ */ private String suit = ""; private String rank = ""; private int cardValue = 0; /** * @return the cardValue */ public int getCardValue() { return cardValue; } /** * @param cardValue * the cardValue to set */ public void setCardValue(int cardValue) { this.cardValue = cardValue; } /** * @return the rank */ public String getRank() { return rank; } /** * @param rank * the rank to set */ public void setRank(String rank) { this.rank = rank; } /** * @return the suit */ public String getSuit() { return suit; } /** * @param suit * the suit to set */ public void setSuit(String suit) { this.suit = suit; } /** * construct a new card with random rank and suit. */ public Card() { int randomSuitIndex = (int) (4 * Math.random()); int randomRankIndex = (int) (13 * Math.random()); this.suit = suitArray[randomSuitIndex]; this.rank = rankArray[randomRankIndex]; this.setCardValue((rankList.indexOf(this.rank) + 1) * 10 + (suitList.indexOf(this.suit) + 1)); } /** * construct a new card with rank and suit in number * @param rankInt * @param suitInt */ public Card(int rankInt, int suitInt) { this.suit = suitArray[suitInt]; this.rank = rankArray[rankInt]; this.setCardValue((rankInt + 1) * 10 + (suitInt + 1)); } @Override public String toString() { String str = ""; str = str + this.rank + "-" + this.suit; return str; } public boolean isGreaterThan(Card c) { if (this.getCardValue() > c.getCardValue()) { return true; } else { return false; } } public static void main(String[] args) { Card c1 = new Card(); Card c2 = new Card(); if (c1.isGreaterThan(c2)) { System.out.println(c1.toString() + " is greater than " + c2.toString()); } else { System.out.println(c2.toString() + " is greater than " + c1.toString()); } } }
Hồi lâu, đây là Nơi tôi chia sẻ những suy nghĩ về công việc và học tập. bây giờ phần lớn thời gian tôi sẽ copy&paste một số bài viết ưng ý để dành đọc lại sau này
Search This Blog
Monday, July 25, 2011
Test cái syntax highlighter coi
Subscribe to:
Post Comments (Atom)
Phật giáo vs cúng sao
Nhiều người nói Phật giáo bây giờ biến tướng, cúng sao giải hạng mê tín dị đoan... Nhưng mất đi cái đó rồi, nhóm những con người có ít họ...
-
Có những điều không trường kinh doanh nào dạy bạn (phần 4). Giá trị cảm nhận của khách hàng là tổng giá trị cảm nhận (total perceived value)...
-
Trích nguồn của linh lũ thiên tôn - thập tứ tỷ. Vâng, cái kết cho ngoại truyện của 1 siêu phẩm, nhạt hơn cả nước loz luôn. Và đây cũng là cm...
-
Tùy chỉnh để Eclipse sử dụng text-encoding là UTF-8 Dùng Eclipse rất sướng, nhưng mặc định thì cái text encoding của nó là CP1252 - không ...
No comments:
Post a Comment