1 public class CardDemo { 2 private String size; 3 private String color; 4 private int index; 5 6 public CardDemo(String size, String color, int index) { 7 this.size = size; 8 this.color = color; 9 this.index = index; 10 } 11 12 public int getIndex() { 13 return index; 14 } 15 16 public void setIndex(int index) { 17 this.index = index; 18 } 19 20 public CardDemo() { 21 } 22 23 public String getSize() { 24 return size; 25 } 26 27 public void setSize(String size) { 28 this.size = size; 29 } 30 31 public String getColor() { 32 return color; 33 } 34 35 public void setColor(String color) { 36 this.color = color; 37 } 38 39 @Override 40 public String toString() { 41 return size + color; 42 } 43 }
1 public class CardGamesDemo { 2 3 // 牌面 {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"}; 4 // 花色 {"♠","♥","♣","♦"}; 5 public static List<CardDemo> allCards = new ArrayList<>(); 6 7 static { 8 // 定义牌面 9 String[] sizes = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"}; 10 // 定义花色 11 String[] colors = {"♠","♥","♣","♦"}; 12 // 定义大小 13 int index = 0; 14 for (String size : sizes) { 15 index ++; 16 for (String color : colors) { 17 CardDemo c = new CardDemo(size, color, index); 18 allCards.add(c); 19 } 20 } 21 22 // 大小王添加到集合中 23 CardDemo small = new CardDemo("", " 标签:index,String,斗地主,color,CardDemo,public,size From: https://www.cnblogs.com/dsds/p/17985732