-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandDealer.java
More file actions
50 lines (41 loc) · 1.38 KB
/
HandDealer.java
File metadata and controls
50 lines (41 loc) · 1.38 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
package com.pslin.cards;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/**
* @author plin
*/
public class HandDealer {
public static void main(String[] args) {
// Create a new deck and shuffle it
Deck deck = new Deck();
Collections.shuffle(deck.getCards());
// Deal the cards
List<Card> player1 = deck.getCards().subList(0, 13);
List<Card> player2 = deck.getCards().subList(13, 26);
List<Card> player3 = deck.getCards().subList(26, 39);
List<Card> player4 = deck.getCards().subList(39, 52);
// Sort hands
Collections.sort(player1);
Collections.sort(player2);
Collections.sort(player3);
Collections.sort(player4);
// Print hands
printHand(player1);
printHand(player2);
printHand(player3);
printHand(player4);
}
private static void printHand(List<Card> hand) {
Iterator<Card> i = hand.iterator();
if(i.hasNext()) {
Card card = i.next();
System.out.print(card.getDisplayValue() + card.getSuit().getUnicode());
}
while(i.hasNext()) {
Card card = i.next();
System.out.print(" : " + card.getDisplayValue() + card.getSuit().getUnicode());
}
System.out.println();
}
}