diff --git a/src/tp03/Card.java b/src/tp03/Card.java new file mode 100644 index 0000000000000000000000000000000000000000..4438314c3f4ff9146991a68cfef0b693ed9a7843 --- /dev/null +++ b/src/tp03/Card.java @@ -0,0 +1,50 @@ +public class Card { + + private Color color; + private Rank rank; + + public Card (Color color, Rank rank) { + this.color = color; + this.rank = rank; + } + + public Card (String color, String rank) { + for (int i = 0; i < Color.values().length; i++) { + if (Color.values()[i].equals(color)) { + this.color = Color.valueOf(color); + } + } + + for (int i = 0; i < Rank.values().length; i++) { + if (Rank.values()[i].equals(color)) { + this.rank = Rank.valueOf(rank); + } + } + } + + public Color getColor() { + return this.color; + } + + public Rank getRank() { + return this.rank; + } + + public boolean equals(Card other) { + if (this == other) { + return true; + } + if (other == null) { + return false; + } + if (this.color.equals(other.color) && this.rank.equals(other.rank)) { + return true; + } + return false; + } + + public String toString() { + return this.rank.toString() + " of " + this.color.toString(); + } + +} \ No newline at end of file diff --git a/src/tp03/Color.java b/src/tp03/Color.java new file mode 100644 index 0000000000000000000000000000000000000000..a62cbfebd237ed453089ac28a647b2b2bea61de1 --- /dev/null +++ b/src/tp03/Color.java @@ -0,0 +1,3 @@ +public enum Color { + CLUB, DIAMOND, HEART, SPADE; +} \ No newline at end of file diff --git a/src/tp03/Rank.java b/src/tp03/Rank.java new file mode 100644 index 0000000000000000000000000000000000000000..2b9f39d354e338b829a45434b873fe90b17133a3 --- /dev/null +++ b/src/tp03/Rank.java @@ -0,0 +1,3 @@ +public enum Rank { + SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE; +} \ No newline at end of file