import java.util.*; public class game { private String size; private String
color; private int idenx; public game() { } public game(String size, String
color,int idenx) { this.size = size; this.color = color;
this.idenx=idenx;// The real size of the card } public int getIdenx() { return idenx; } public void
setIdenx(int idenx) { this.idenx = idenx; } public String getSize() { return
size; } public void setSize(String size) { this.size = size; } public String
getColor() { return color; } public void setColor(String color) { this.color =
color; } @Override public String toString() { return size+color; } } class
gametext{ // Define a static collection store 54 Card public static List<game> allcards=new ArrayList<>();
// Define static code block initialization card data static{// Define points and decors String
sizes[]={"3","4","5","6","7","8","9","10","J","Q","K","A","2"}; String
colors[]={"♥","♠","♦","♣"}; // Combine points and decors int idenx=0;// Size of record board for(String
size:sizes){ idenx++; for(String color:colors){ // Encapsulate into a card object game g=new
game(size,color,idenx); // Save it in the collection container allcards.add(g); } } // Save size to ♚ king ♔ Xiao Wang game
g1=new game("","♚",++idenx); game g2=new game("","♔",++idenx);
Collections.addAll(allcards,g1,g2); System.out.println(" New card :"+allcards); }
public static void main(String[] args) { // shuffle the cards
Collections.shuffle(allcards);// Disrupt collection elements System.out.println(" After shuffling :"+allcards);
// Licensing , Define three players , take 51 Cards are given to three players , The last three cards are treated as landlords List<game> zhangsan=new ArrayList<>();
List<game> Lisi=new ArrayList<>(); List<game> wangwu=new ArrayList<>(); for
(int i = 0; i < allcards.size(); i++) { // Get the current card object game g=allcards.get(i);
if(i%3==0){ //zhangsan Pick up the card zhangsan.add(g); }else if(i%3==1){ //Lisi Pick up the card
Lisi.add(g); }else if(i%3==2){ //wangwu Pick up the card wangwu.add(g); } }
// Get the last three cards , Cut the last three cards into a word set List<game>
eventual=allcards.subList(allcards.size()-3,allcards.size()); // Sort players' cards
sortcard(zhangsan); sortcard(Lisi); sortcard(wangwu); // Output player's cards
System.out.println(" Zhang San :"+zhangsan); System.out.println(" Li Si :"+Lisi);
System.out.println(" Wang Wu :"+wangwu); System.out.println(" Three main cards :"+eventual); }
private static void sortcard(List<game> games) { Collections.sort(games, new
Comparator<game>() { @Override public int compare(game o1, game o2) { return
o1.getIdenx()-o2.getIdenx(); } }); } }

Technology
Daily Recommendation
views 267
views 232
views 231