forked from prmr/SoftwareDesignCode
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCardWithDesign.java
66 lines (46 loc) · 1.35 KB
/
CardWithDesign.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package ca.mcgill.cs.swdesign.m3.demo;
public class CardWithDesign extends Card {
public enum Design{ CLASSIC, ARTISTIC, FUN}
Design aStyle;
public CardWithDesign(Rank pRank, Suit pSuit, Design pStyle) {
super(pRank, pSuit);
this.aStyle = pStyle;
}
public CardWithDesign(Design pStyle) {
super();
this.aStyle = pStyle;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((aStyle == null) ? 0 : aStyle.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
CardWithDesign other = (CardWithDesign) obj;
if (aStyle != other.aStyle)
return false;
return true;
}
/**
* This is the driver program.
* @param args
*/
public static void main(String[] args){
Card card1 = new CardWithDesign(Card.Rank.FOUR, Card.Suit.CLUBS, CardWithDesign.Design.ARTISTIC);
Card card2 = new CardWithDesign(Card.Rank.FOUR, Card.Suit.CLUBS, CardWithDesign.Design.CLASSIC);
System.out.println(card1.equals(card2));
Card card3 = new Card(Card.Rank.FOUR, Card.Suit.CLUBS);
System.out.println(card1.equals(card3));
System.out.println(card3.equals(card1));
System.out.println(card2.equals(card3));
}
}