-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathReadIn.java
More file actions
93 lines (77 loc) · 2.11 KB
/
Copy pathReadIn.java
File metadata and controls
93 lines (77 loc) · 2.11 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
81
82
83
84
85
86
87
88
89
90
91
92
93
package peterson;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
public class ReadIn {
public final static int TEN = 10;
public final static int JACK = 11;
public final static int QUEEN = 12;
public final static int KING = 13;
public final static int ACE = 14;
public final static int SPADE = 1;
public final static int HEART = 10;
public final static int DIAMOND = 100;
public final static int CLUB = 1000;
Scanner scan = new Scanner(new File("hands.txt"));
String str;
int d, s, playerOneWins, playerTwoWins, count = 0;
Card card;
Card[] hand1 = new Card[5];
Card[] hand2 = new Card[5];
CheckHand check = new CheckHand();
public ReadIn() throws IOException {
// READ IN FILE
while (scan.hasNext()) {
str = scan.next();
// IF 10, J, K, Q, A.....
if (str.substring(0, 1).equals("T"))
d = TEN;
else if (str.substring(0, 1).equals("J"))
d = JACK;
else if (str.substring(0, 1).equals("Q"))
d = QUEEN;
else if (str.substring(0, 1).equals("K"))
d = KING;
else if (str.substring(0, 1).equals("A"))
d = ACE;
else
d = Integer.parseInt(str.substring(0, 1));
// TURNS SUIT INTO INT
if (str.substring(1).equals("S"))
s = SPADE;
else if (str.substring(1).equals("H"))
s = HEART;
else if (str.substring(1).equals("D"))
s = DIAMOND;
else
s = CLUB;
// NEW CARD FROM DIGIT:SUIT INPUT
card = new Card(d, s);
// SEPARATE CARDS INTO TWO HANDS
if (count < 5) {
hand1[count] = card;
} else if (count >= 5 && count < 10) {
hand2[count % 5] = card;
}
count++;
// RESET COUNT TO 0 TO GET NEXT SET OF HANDS
if (count == 10) {
// CHECK HAND TO SEE WHO WON
if (check.checkHand(hand1) > check.checkHand(hand2))
playerOneWins++;
else
playerTwoWins++;
count = 0;
}
}
// OUTPUT OF WINNER
System.out.println("Player One Has: " + playerOneWins + "\n"
+ "Player Two Has: " + playerTwoWins);
if (playerOneWins > playerTwoWins)
System.out.println("Player One Wins!!!");
else
System.out.println("Player Two Wins!!!");
// CLOSE SCANNER
scan.close();
}
}