-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoneTrickOneTaker.java
More file actions
26 lines (26 loc) · 994 Bytes
/
oneTrickOneTaker.java
File metadata and controls
26 lines (26 loc) · 994 Bytes
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
import java.util.*;
public class oneTrickOneTaker {
public static String winnerOfTrick(String[] cards, String[] players) {
// ...gHappy gCoding !
String suit = cards[0].substring(1);
int index = 0;
int highestIndex = 0;
int highestVal = Integer.MIN_VALUE;
String conversion = "0123456789TJQKA";
for(String card : cards){
System.out.println(card);
if(card.substring(1).equals(suit)){
System.out.println(card.substring(1));
if(conversion.indexOf(card.substring(0, 1)) > highestVal){
highestVal = conversion.indexOf(card.substring(0, 1));
highestIndex = index;
}
}
index++;
}
return players[highestIndex] + " wins";
}
public static void main(String[] args) {
System.out.println(winnerOfTrick(new String[]{"3H","KH","8C","AH"}, new String[]{"a","b","c","d"}));
}
}