-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCard.java
More file actions
55 lines (52 loc) · 1.48 KB
/
Card.java
File metadata and controls
55 lines (52 loc) · 1.48 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
//creates card objects to store information about them and returns information for other methods to use
public class Card
{
private int number; // requirement 18
private int suitValue;
private static String[] suitOptions = {"diamonds", "clubs", "hearts", "spades"};
private String suit;
private String cardName; // requirement 1d
//creates a card by picking # 2-14 for value, 0-4 for suit, and using that creates the name of the card to show user
public Card() // requirement 19
{
number = (int) (Math.random() * 13) + 2; // requirement 9
suitValue = (int) (Math.random() * 4);
if (number == 14) // requirement 10*
{
cardName = "A" + " of " + suitOptions[suitValue];
}
else if (number < 11)
{
cardName = number + " of " + suitOptions[suitValue];
}
else if (number == 11)
{
cardName = "J" + " of " + suitOptions[suitValue];
}
else if (number == 12)
{
cardName = "Q" + " of " + suitOptions[suitValue];
}
else
{
cardName = "K" + " of " + suitOptions[suitValue];
}
}
//accessor methods
public int getNumber() // requirement 20
{
return number; // requirement 5
}
public int getSuit()
{
return suitValue;
}
public String getCardName()
{
return cardName;
}
public String toString()
{
return cardName;
}
}