forked from srinathr91/TestJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvent.java
More file actions
80 lines (77 loc) · 1.5 KB
/
Event.java
File metadata and controls
80 lines (77 loc) · 1.5 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
import java.util.Random;
import java.util.*;
public class Event{
public enum Type{DIAMOND,SPADE,HEARTS,CLUB}
public class Card{
private Type type;
private int rank;
public Type getType(){
return type;
}
public int getRank(){
return rank;
}
public Card(Type type,int rank){
this.rank=rank;
this.type=type;
}
}
private static ArrayList<Card> dec;
/*public void setDec(ArrayList<Card> dec){
this.dec=dec;
}*/
public ArrayList<Card> getDec(){
return dec;
}
public void fillDec(){
ArrayList<Card> dec1=new ArrayList<Card>();
for(int i=0;i<13;i++){
Card card=new Card(Type.DIAMOND,i);
dec1.add(card);
}
for(int i=0;i<13;i++){
Card card=new Card(Type.SPADE,i);
dec1.add(card);
}
for(int i=0;i<13;i++){
Card card=new Card(Type.HEARTS,i);
dec1.add(card);
}
for(int i=0;i<13;i++){
Card card=new Card(Type.CLUB,i);
dec1.add(card);
}
dec=dec1;
}
public static void mix(){
Collections.shuffle(dec);
}
public Card draw1(){
fillDec();
mix();
Card cc=Event.dec.remove(0);
return cc;
}
public Card draw(){
Random rr=new Random();
int r1 = rr.nextInt(4);
Type type;
if(r1==0){
type=Type.DIAMOND;}
else if(r1==1){
type=Type.SPADE;}
else if(r1==2){
type=Type.HEARTS;}
else{
type=Type.CLUB;}
int r2 = rr.nextInt(13);
Card cc=new Card(type,r2);
return cc;
}
public static void main(String[] args){
Event ee =new Event();
Card c=ee.draw1();
System.out.println(c.getRank());
System.out.println(c.getType());
}
}