Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. public class CardTester_Qumsieh
  4. {
  5. public static void main( String[] args )
  6. {
  7.  
  8. }
  9.  
  10. class Card
  11. {
  12. int suit;
  13. int rank;
  14. int pointValue;
  15.  
  16. /**
  17. * Creates a new <code>Card</code> instance.
  18. *
  19. * @param cardRank a <code>String</code> value
  20. * containing the rank of the card
  21. * @param cardSuit a <code>String</code> value
  22. * containing the suit of the card
  23. * @param cardPointValue an <code>int</code> value
  24. * containing the point value of the card
  25. */
  26. public Card(String cardRank, String cardSuit, int cardPointValue) {
  27. switch(cardSuit) {
  28. case("Hearts"): suit = 0;
  29. case("Diamonds"): suit = 1;
  30. case("Clubs"): suit = 2;
  31. case("Spades"): suit = 3;
  32. }
  33. pointValue = cardPointValue;
  34. }
  35.  
  36.  
  37. /**
  38. * Accesses this <code>Card's</code> suit.
  39. * @return this <code>Card's</code> suit.
  40. */
  41. public String suit() {
  42. return "" + suit;
  43. }
  44.  
  45. /**
  46. * Accesses this <code>Card's</code> rank.
  47. * @return this <code>Card's</code> rank.
  48. */
  49. public String rank() {
  50. return "" + rank;
  51. }
  52.  
  53. /**
  54. * Accesses this <code>Card's</code> point value.
  55. * @return this <code>Card's</code> point value.
  56. */
  57. public int pointValue() {
  58. return this.pointValue;
  59. }
  60.  
  61. /** Compare this card with the argument.
  62. * @param otherCard the other card to compare to this
  63. * @return true if the rank, suit, and point value of this card
  64. * are equal to those of the argument;
  65. * false otherwise.
  66. */
  67. public boolean matches(Card otherCard) {
  68. return (suit == otherCard.suit && rank == otherCard.rank && pointValue == otherCard.pointValue);
  69. }
  70.  
  71. /**
  72. * Converts the rank, suit, and point value into a string in the format
  73. * "[Rank] of [Suit] (point value = [PointValue])".
  74. * This provides a useful way of printing the contents
  75. * of a <code>Deck</code> in an easily readable format or performing
  76. * other similar functions.
  77. *
  78. * @return a <code>String</code> containing the rank, suit,
  79. * and point value of the card.
  80. */
  81. @Override
  82. public String toString() {
  83. return suit + " of " + rank + "(Point: " + pointValue + ")";
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement