扑克牌

package com.company;

import java.util.*;

public class cards {
    private List<card> 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<card> 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<card> 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();

    }
}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 随机抽出5张牌,判断抽出的5张牌是不是连续的扑克牌,不许使用排序算法。 程序输出如下:
    FredricZhu阅读 4,026评论 0 0
  • 这两日儿子总是做噩梦。昨晚洗漱前他大声喊着不要噩梦,不要噩梦。这已不是我第一次看到他如此和自己做斗争。很佩服他! ...
    赵芊阅读 1,228评论 0 0
  • 我记笔记的方法记笔记是很多人学习中要用到的。近日对记笔记的方法进行了整理。一、原来记笔记中存在的问题1.在纸质笔记...
    ayhzh阅读 937评论 0 0
  • 我的头像就是豆豆 豆豆真是一只傻猫 她是我曾经最爱的人送给我的 她被我前女友在她两个月时,藏在小包里夹带上的高铁,...
    060f8225a004阅读 3,003评论 0 0