創建撲克牌測試(一)
阿新 • • 發佈:2018-03-17
Java List 1.Main
public class Main { /** * 1.面向對象思維(一張撲克) * 抽取共性屬性 * 花色 int * 牌值 int * 花色符號 String * 牌值符號 String * 抽取共性方法 * * 2.面向對象思維(一副撲克) * 抽取共性屬性 * 花色數量 int * 牌的張數 int * 所有牌 List * 抽取共性方法 * 創建撲克 * 洗牌 * 抽取一張 * 分組 * 排序 * 1(多)--對--2(一) * */ public static void main(String[] args) { // TODO Auto-generated method stub } }
2.Apuke(一張撲克)
//一張撲克類 public class Apuke { /** * 1.定義屬性 * */ private int color; // 花色值 private String colorText; // 花色符號 private int value; // 牌值 private String valueText; // 牌值符號 /** * 2.創建構造方法和setter、getter方法、toString方法 * */ public Apuke(int color, String colorText, int value, String valueText) { super(); this.color = color; this.colorText = colorText; this.value = value; this.valueText = valueText; } public int getColor() { return color; } public void setColor(int color) { this.color = color; } public String getColorText() { return colorText; } public void setColorText(String colorText) { this.colorText = colorText; } public int getValue() { return value; } public void setValue(int value) { this.value = value; } public String getValueText() { return valueText; } public void setValueText(String valueText) { this.valueText = valueText; } @Override public String toString() { return "Apuke [color=" + color + ", colorText=" + colorText + ", value=" + value + ", valueText=" + valueText + "]"; } }
3.Pukes(一副撲克)
import java.util.List; // 一副撲克 public class Pukes { /** * 3.定義屬性 * */ private int pukesCount; // 撲克張數 private int colorCount; // 花色數量 private List<Apuke> aList; // 撲克牌的集合 /** * 4.創建setter、getter方法、toString方法 * */ public int getPukesCount() { return pukesCount; } public void setPukesCount(int pukesCount) { this.pukesCount = pukesCount; } public int getColorCount() { return colorCount; } public void setColorCount(int colorCount) { this.colorCount = colorCount; } public List<Apuke> getaList() { return aList; } public void setaList(List<Apuke> aList) { this.aList = aList; } @Override public String toString() { return "Pukes [pukesCount=" + pukesCount + ", colorCount=" + colorCount + ", aList=" + aList + "]"; } /** * 5.先把業務方法定義出來,可以先搭個架子 * */ // 5.1.創建一副撲克牌的方法 public List<Apuke> createPuke(){ return null; } // 5.2.洗牌的方法 public List<Apuke> shufferPuke(){ return null; } // 5.3.隨機抽取一張撲克 public Apuke getRandomPuke() { return null; } // 5.4.排序所有撲克牌 public List<Apuke> sortPuke(){ return null; } // 5.5.分組最後做 }
創建撲克牌測試(一)