-
Notifications
You must be signed in to change notification settings - Fork 9
/
Card.java
executable file
·97 lines (79 loc) · 1.83 KB
/
Card.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
public class Card
{
private int quantity;
private int color;
private int shading;
private int shape;
public Card(int theQuantity, int theColor, int theShading, int theShape)
{
quantity = fixValue(theQuantity);
color = fixValue(theColor);
shading = fixValue(theShading);
shape = fixValue(theShape);
}
private int fixValue(int value)
{
value = value % 3;
if(value <= 0)
value += 3;
return value;
}
public int getQuantity()
{
return quantity;
}
public int getColor()
{
return color;
}
public int getShading()
{
return shading;
}
public int getShape()
{
return shape;
}
public boolean isSet(Card c2, Card c3)
{
int quantitySum = quantity + c2.getQuantity() + c3.getQuantity();
int colorSum = color + c2.getColor() + c3.getColor();
int shadingSum = shading + c2.getShading() + c3.getShading();
int shapeSum = shape + c2.getShape() + c3.getShape();
return quantitySum % 3 == 0 && colorSum % 3 == 0 &&
shadingSum % 3 == 0 && shapeSum % 3 == 0;
}
public String toString()
{
char colorVal;
char shadingVal;
char shapeVal;
if(color == 1)
colorVal = 'R';
else if(color == 2)
colorVal = 'G';
else
colorVal = 'P';
if(shading == 1)
shadingVal = 'O';
else if(shading == 2)
shadingVal = 'T';
else
shadingVal = 'S';
if(shape == 1)
shapeVal = 'O';
else if(shape == 2)
shapeVal = 'D';
else
shapeVal = 'S';
return "" + quantity + colorVal + shadingVal + shapeVal;
}
public boolean equals(Object obj)
{
Card that = (Card)obj;
return quantity == that.getQuantity() &&
color == that.getColor() &&
shading == that.getShading() &&
shape == that.getShape();
}
}