Guest User

Untitled

a guest
Feb 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. public class Card {
  2. public static final int HEARTS = 0;
  3. public static final int DIAMONDS = 1;
  4. public static final int CLUBS = 2;
  5. public static final int SPADES = 3;
  6.  
  7. private int suit; //says what suit the card is (one of the above 4)
  8. private int rank; //says what number (or face card) it is J=11, Q=12, K=13
  9.  
  10. public Card(int suit, int rank) {
  11. this.suit = suit;
  12. this.rank = rank;
  13. }
  14.  
  15. /**
  16. * Returns a string like "Ace of spades" or "9 of diamonds"
  17. */
  18. public String toString() {
  19. return rank() + " of " + suit();
  20. }
  21.  
  22. /**
  23. * Returns the rank of the card as a string
  24. * @return the rank of the card as a string.
  25. */
  26. private String rank() {
  27. if (rank == 13) {
  28. return "King";
  29. }
  30. else if (rank == 12) {
  31. return "Queen";
  32. }
  33. else if (rank == 11) {
  34. return "Jack";
  35. }
  36. else if (rank == 1) {
  37. return "Ace";
  38. }
  39. else {
  40. return rank + "";
  41. }
  42. }
  43.  
  44. /**
  45. * Returns the suit of the card as a string.
  46. * @return the suit of the card as a string.
  47. */
  48. private String suit() {
  49. if (suit == HEARTS) {
  50. return "hearts";
  51. }
  52. else if (suit == DIAMONDS) {
  53. return "diamonds";
  54. }
  55. else if (suit == SPADES) {
  56. return "spades";
  57. }
  58. else {
  59. return "clubs";
  60. }
  61. }
  62.  
  63. }
Add Comment
Please, Sign In to add comment