-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCard.java
More file actions
131 lines (122 loc) · 3.09 KB
/
Copy pathCard.java
File metadata and controls
131 lines (122 loc) · 3.09 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
* The Card class defines a playing card and the methods an object
* of the Card class can use.
* @author Russell Yang
* @version 11/9/17
*/
public class Card
{
/**
* Instance variables
*/
private int rank; //stores the rank of a card
private String suit; //stores the suit of a card
private boolean isFaceUp; //stores whether the card is face up
/**
* Constructor with parameters; initializes instance variables.
* @param initRank an initial rank of a card
* @param initSuit an initial suit of a card
*/
public Card(int initRank, String initSuit)
{
rank = initRank;
suit = initSuit;
isFaceUp = false;
}
/**
* Gets the rank of the card.
* @postcondition the rank of the card is returned.
* @return the rank of the card.
*/
public int getRank()
{
return rank;
}
/**
* Gets the suit of the card.
* @postcondition the suit of the card is returned.
* @return the suit of the card.
*/
public String getSuit()
{
return suit;
}
/**
* Checks whether the card is red.
* @postcondition true is returned if the card is a diamond
* or heart (red cards), false otherwise
* @return true if the card is red, false otherwise.
*/
public boolean isRed()
{
return(suit.equals("d") || suit.equals("h"));
}
/**
* Checks if the card is face up.
* @postcondition true is returned if the card is face up, false otherwise.
* @return true if the card is face up, false otherwise.
*/
public boolean isFaceUp()
{
return isFaceUp;
}
/**
* Turns the card to face up.
* @postcondition isFaceUp is set to true.
*/
public void turnUp()
{
isFaceUp = true;
}
/**
* Turns the card to face down.
* @postcondition isFaceUp is set to false.
*/
public void turnDown()
{
isFaceUp = false;
}
/**
* Gets the file name of a card.
* @postcondition the file name of a card is returned.
* @return the file name of the card.
*/
public String getFileName()
{
String firstPart = "cards\\";
String lastPart = ".gif";
if(!isFaceUp)
{
return firstPart + "back" + lastPart;
}
else
{
String middlePart = getSuit();
if(rank==1)
{
middlePart = "a" + middlePart;
}
else if(rank==10)
{
middlePart = "t" + middlePart;
}
else if(rank==11)
{
middlePart = "j" + middlePart;
}
else if(rank==12)
{
middlePart = "q" + middlePart;
}
else if(rank==13)
{
middlePart = "k" + middlePart;
}
else
{
middlePart = getRank() + middlePart;
}
return firstPart + middlePart + lastPart;
}
}
}