经历半年的学习,终于搞定了,欢迎大家讨论!
//扑克类; public class Poker { private String flower; private String number; public String getFlower() { return flower; } public void setFlower(String flower) { this.flower = flower; } public String getNumber() { return number; } public void setNumber(String number) { this.number = number; } public Poker(String flower, String number) { this.flower = flower; this.number = number; } } //玩家类 public class Player { private String name; private int id; private ArrayList <Poker>myPoker= new ArrayList<Poker>(); public String getName() { return name; } public void setName(String name) { this.name = name; } public int getId() { return id; } public void setId(int id) { this.id = id; } public ArrayList<Poker> getMyPoker() { return myPoker; } public void setMyPoker(Poker poker) { this.myPoker.add(poker); } public Player(String name, int id) { this.name = name; this.id = id; this.myPoker = myPoker; } //显示玩家手牌 public void show(){ System.out.print("玩家"+getName()+": "); for (Poker p : myPoker) { System.out.print(p.getFlower()+p.getNumber()+" "); } System.out.println(); } //玩家获胜信息 public void winShow(Player p){ System.out.println("-----玩家"+p.getName()+"获胜!-----"); } }
结果。