import java.util.Arrays;
import java.util.Collections;
import java.util.List;
//扑克牌类
class Card {
//扑克牌点数
public static enum Face
{
ACE,Deuce,Three,Four,Five,Six,Seven,Eight,Nine,Ten,Jack,Queen,King
};
//扑克牌花色
public static enum Suit{Clubs,Diamonds,Hearts,Spades};
private final Face face;
private final Suit suit;
public Card(Face face,Suit suit)
{
this.face=face;
this.suit=suit;
}
public Face getFace() {
return face;
}
public Suit getSuit() {
return suit;
}
public String getCard()
{
return String.format("%s,%s",face,suit);
}
}
//牌桌类
class DeckOfCard
{
private List<Card> list;
//初始化牌桌,并进行洗牌
public DeckOfCard()
{
Card[] deck=new Card[52];
int count=0;
//用Card对象填充牌桌
for (Card.Suit suit:Card.Suit.values()) {
for ( Card.Face face:Card.Face.values() ) {
deck[count++] =new Card(face, suit);
}
}
list = Arrays.asList(deck); //将数组转换成list
Collections.shuffle(list); //洗牌
}
public void printcards()
{
//按4列显示52张牌
for ( int i=0; i<list.size(); i++ )
//格式化输出
System.out.printf( "%-19s%s", list.get(i).getCard(),
((i+1)%4==0)?"\n":"" );
}
}
//公共类(发牌者)
public class Dealer
{
public static void main(String[] args) {
DeckOfCard deckOfCard=new DeckOfCard();
deckOfCard.printcards();
}
}