七毛萨玛
2015-08-07 22:03
package imooc_puke; //扑克牌类 public class Poker { private String colour;//花色 private String num;//点数 //get set方法 及构造函数 public String getColour() { return colour; } public void setColour(String colour) { this.colour = colour; } public String getNum() { return num; } public void setNum(String num) { this.num = num; } public Poker(String colour, String num) { super(); this.colour = colour; this.num = num; } public Poker() { super(); } } //牌堆类 package imooc_puke; import java.util.ArrayList; import java.util.List; public class Pile extends Poker { public Pile() { String[] colour = { "黑桃", "红桃", "梅花", "方片" }; String[] num = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A" }; List<Poker> piles = new ArrayList<Poker>();//创建牌堆集合 //二重循环得到所有花色和点数的组合 for (int i = 0; i < colour.length; i++) { for (int j = 0; j < num.length; j++) { Poker p = new Poker(colour[i], num[j]);//将得到的所有花色和点数的组合创建扑克牌对象 piles.add(p);//将所有对象添加到牌堆集合 } } //遍历牌堆打印出所有扑克牌 for (Poker pk : piles) { System.out.print(pk.getColour() + " " + pk.getNum()); } } //测试打印 public static void main(String[] args) { Pile p=new Pile(); } }
very good!
Java入门第三季
409792 学习 · 4340 问题
相似问题