-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCard.java
More file actions
60 lines (51 loc) · 1.15 KB
/
Card.java
File metadata and controls
60 lines (51 loc) · 1.15 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
import java.util.Random;
public class Card {
private String suit;
private int value;
public Card() {
this.suit = getRandomSuit();
this.value = getRandomVal();
}
public String getSuit() {
return this.suit;
}
public int getValue() {
return this.value;
}
public void showCard() {
System.out.println("Card: " + this.getSuit() + " " + this.getValue());
}
private int getRandomVal() {
Random random = new Random();
return random.nextInt(13) + 1;
}
private String getRandomSuit() {
Random random = new Random();
int idx = random.nextInt(4);
String suit = "";
switch(idx) {
case 0:
suit = "heart♥";
break;
case 1:
suit = "spade♠";
break;
case 2:
suit = "diamond♦";
break;
case 3:
suit = "club♣";
break;
}
return suit;
}
}
/* card
* Attributes
* 1. suit
* 2. value
* Functions
* 1. getSuit
* 2. getValue
* 3. showCard
*/