扑克牌

package com.company;

import java.util.*;

public class cards {
    private List cardList = new ArrayList<>();
    private String[] colors = new String[]{"红桃","黑桃","方片","草花"};
    public cards(){}

    public void init(){
        for (int i = 0;i < 4;i++){
            for (int j = 1;j < 14;j++){
                card card = new card();
                card.setColor(colors[i]);
                card.setValue(j);
                cardList.add(card);
            }
        }
    }
    public void print(){
        for (int j = 0;j < cardList.size();j++){
            if (j %13 == 0){
                System.out.println();
            }
            System.out.print(cardList.get(j).getColor()+cardList.get(j).getValue()+" ");

        }
    }

    public void xipai(){
        Collections.shuffle(cardList);
    }
    public List fapai(){
        List cardList1 = new ArrayList<>();
        for (int i = 0;i < 5;i++){
            Random random = new Random();
            int index = random.nextInt(cardList.size());
            cardList1.add(cardList.get(index));
        }
        return cardList1;
    }
    public void print(List cardList1){
        for (int j = 0;j < cardList1.size();j++){

            System.out.print(cardList1.get(j).getColor()+cardList1.get(j).getValue()+" ");

        }
    }
}


package com.company;

public class card {
    private String color;
    private int value;

    public card(){}
    public card(String color,int value){
        this.color = color;
        this.value = value;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }
}


package com.company;

public class card {
    private String color;
    private int value;

    public card(){}
    public card(String color,int value){
        this.color = color;
        this.value = value;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }
}


package com.company;

public class testcards {
    public static void main(String[] args) {
        cards cards = new cards();
        cards.init();
        cards.print();

    }
}

你可能感兴趣的:(扑克牌)