-
Notifications
You must be signed in to change notification settings - Fork 0
/
Card.java
96 lines (80 loc) · 2.14 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
/*
Nidhi Singh
CS 110(A)
Assignment #5.3
The Card Class
*/
/**
The Card class stimulates the cards game
*/
public class Card
{
//fields
public final static int SPADES = 0; // Codes for the 4 suits
public final static int CLUBS = 1;
public final static int HEARTS = 2;
public final static int DIAMONDS = 3;
public final static int ACE = 1; // Codes for the non-numeric cards.
public final static int JACK = 11; // Cards 2 through 10 have their
public final static int QUEEN = 12; // numerical values for their codes.
public final static int KING = 13;
private int rank;
private int suit;
/* Constructor
Card initilizes the suit and rank variable
@param suit The number of the suit from the main method
@param rank The rank of the cards
**/
public Card(int suit, int rank)
{
this.suit = suit;
this.rank = rank;
}
/**
the getSuit method returns the suit variable
@return The int value associated with the variable suit
*/
public int getSuit()
{
return suit;
}
/**
the getRank method returns the rank variable
@return The int value associated with the variable rank
*/
public int getRank()
{
return rank;
}
/**
the toString method returns the output as a string. It first finds a proper value for both the variables
@return The String for the output
*/
public String toString()
{
String suitName;
if (suit == SPADES)
suitName = "SPADES";
else if (suit == CLUBS)
suitName = "CLUBS";
else if (suit == HEARTS)
suitName = "HEARTS";
else
suitName = "DIAMONDS";
// String str1 = "The suit is " + suitName;
// String str2 = "The rank is " + getRank();
// return str1+"\n"+str2;
return suitName + " " + getRank();
}
/**
the equals method compares the two card numbers
@return The boolean value for the comparison
*/
public boolean equals(Card otherCard)
{
if (rank == otherCard.getRank())
return true;
else
return false;
}
}