编写一个扑克类(每张扑克有花色和数值,例如红心A,草花10),将52张扑克牌放到集合中(自己去选择集合类) 编写3个方法 方法1.将集合中的所有扑克重新洗牌,并将扑克输出(打印出来即可) 方法2

/**
 * Created by whp on 2018/8/1.
 */
public class Poker {
    String color;
    String number;

    public Poker(String color, String number) {
        this.color = color;
        this.number = number;
    }

    @Override
    public String toString() {
        return "["+this.color+this.number+"]";
    }
}


/**
 * Created by whp on 2018/8/1.
 */
public class PokerFounction {
    String[] colors={"黑心","红心","草花","方块"};
    String[] numbers={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
    ArrayList list=new ArrayList();

    public ArrayList createPoker(){
        for(int i=0;ifor(int j=0;jnew Poker(colors[i],numbers[j]));
            }
        }
        return list;
    }

    public void shufflePoker(ArrayList pokers){
        Random random=new Random();
        for(int i=0;i<100;i++) {
            int index1 = random.nextInt(pokers.size());
            int index2 = random.nextInt(pokers.size());
            Poker poker1 = (Poker) list.get(index1);
            Poker poker2 = (Poker) list.get(index2);
            pokers.set(index1, poker2);
            pokers.set(index2, poker1);
        }
    }

    public void showPoker(ArrayList pokers){
        for(int i=0;iif(i%13==12){
                System.out.println();
            }
        }
    }
}


/**
 * Created by whp on 2018/8/1.
 * 编写一个扑克类(每张扑克有花色和数值,例如红心A,草花10),将52张扑克牌放到集合中(自己去选择集合类)
 编写3个方法
 方法1.将集合中的所有扑克重新洗牌,并将扑克输出(打印出来即可)
 方法2.将集合中的所有扑克排序(按方块3~方块2,草花3~草花2, 红心3~红心2, 黑桃3~黑桃2的顺序排序)
 方法3:比较两张扑克牌的大小,如果版面的值相等,则按(黑桃->红心->草花->方块)的顺序进行排列
 测试以上方法

 */
public class Test {
    public static void main(String[] args) {
        PokerFounction pf=new PokerFounction();
        ArrayList pockers=pf.createPoker();
        pf.shufflePoker(pockers);
        pf.showPoker(pockers);
    }
}

你可能感兴趣的:(编写一个扑克类(每张扑克有花色和数值,例如红心A,草花10),将52张扑克牌放到集合中(自己去选择集合类) 编写3个方法 方法1.将集合中的所有扑克重新洗牌,并将扑克输出(打印出来即可) 方法2)