Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. package ija.ija2016.homework2.model.cards;
  2.  
  3. public interface Card {
  4. //nested class Card.Color- Výčtový typ reprezentující barvu karty.
  5.  
  6. enum Color {
  7. CLUBS,
  8. DIAMONDS,
  9. HEARTS,
  10. SPADES;
  11.  
  12.  
  13. @Override
  14. public String toString() {
  15. switch (this) {
  16. case CLUBS:
  17. return "C";
  18. case DIAMONDS:
  19. return "D";
  20. case HEARTS:
  21. return "H";
  22. case SPADES:
  23. return "S";
  24. default:
  25. throw new IllegalArgumentException();
  26. }
  27. }
  28. }
  29.  
  30. Color color();
  31. int compareValue(Card c);
  32. boolean isTurnedFaceUp();
  33. boolean similarColorTo(Card c);
  34. boolean turnFaceUp();
  35. int value();
  36. }
  37. class CardClass implements Card{
  38. private int value;
  39. private boolean face;
  40. private Color color;
  41.  
  42. public Color color(){
  43. return this.color;
  44. }
  45.  
  46. public int value(){
  47. return this.value;
  48. }
  49.  
  50. public boolean similarColorTo(Card c){
  51. if ((this.color == Color.HEARTS || this.color == Color.DIAMONDS) && (c.color == Color.HEARTS || c.color == Color.DIAMONDS)) {
  52. return true;
  53. }
  54. if ( (this.color == Color.CLUBS || this.color == Color.SPADES) && (c.color == Color.CLUBS || c.color == Color.SPADES) ){
  55. return true;
  56. }
  57. return false;
  58. }
  59.  
  60.  
  61. public boolean isTurnedFaceUp(){
  62. return this.face;
  63. }
  64.  
  65. public boolean turnFaceUp(){
  66. if (this.face == false){
  67. this.face = true;
  68. return true;
  69. }
  70. return false;
  71. }
  72.  
  73. public int compareValue(Card c){
  74. return this.value - c.value;
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement