-
Notifications
You must be signed in to change notification settings - Fork 0
/
nonclient class 2
68 lines (63 loc) · 1.67 KB
/
nonclient class 2
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
/******************************************************************************
Eric Zhang
Comp Sci 3
March 23, 2021
High-Low Program
*******************************************************************************/
public class Deck
{
private int cardsdealt;
private Card [] deck;
//Default constructor - only needs this
//because we only make the same deck of cards
public Deck ()
{
String [] suits = {"Hearts", "Diamonds", "Spades", "Clubs"};
cardsdealt = 0;
Card card;
int cardnum = 0;
deck = new Card [52]; //Card # 0 - 51
for (String suit: suits)
{
for (int i = 1; i <= 13; i++)
{
card = new Card (i , suit);
deck [cardnum] = card;
cardnum++;
}
}
}
//create a nested for loop
// 1 - to keep track of suit
// 1 - to keep track of value
//shuffle cards
public void shuffle ()
{
int rand;
int i;
Card temp;
for (i = 0; i <= 51; i++)
{
rand = (int)(Math.random () * 52); //picks a number from 0-51
//swap them
temp = deck [i];
deck [i] = deck[rand];
deck [rand] = temp;
}
cardsdealt = 0;
}
//deal cards
public Card dealcard ()
{
if (cardsdealt == 52)
{
throw new IllegalStateException ("No cards Left in the deck!");
}
else
{
cardsdealt++;
//deal the card off the top of the deck
return deck[cardsdealt - 1];
}
}
}