扑克牌洗牌

今天用老师这两天说的集合框架写了一个扑克牌洗牌的小项目,感觉写得好复杂,希望大家能指出我的缺点

import java.util.*;
class Demo
{
    public static void main(String[] args)
    {
        String[] color = {"黑桃","红桃","梅花","方块"};
        String[] number = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
        StackList list = new StackList();
       
        for (int i = 0;i < 4 ;i++ )
        {
            for (int j = 0;j < 13 ;j++ )
            {
                list.add(new Poker(color[i],number[j]));
            }
        }
       
        System.out.println(list.list);
       
        Random random = new Random();
        int a = 0;
        
        StackList newList = new StackList();
        
        while (a < 52)
        { 
             Object poker = list.get(random.nextInt(52));
            
             if (!newList.contains(poker))
             {
                 newList.add(poker);
             }
             a = newList.size();
        }
        
        System.out.println("\n\n洗完牌后:" + newList.list);
    }
}
class Poker
{
   
    String color;
   
    String number;
    
    public Poker(String color,String number){
         this.color = color;
         this.number = number;
    }
    
    public String toString(){
         return color + number;
    }
    public boolean equals(Object obj){
        Poker n = (Poker)obj;
        return this.color.equals(n.color) && this.number.equals(n.number);
    }
}
class StackList
{
    LinkedList list;
    public StackList(){
          list = new LinkedList();
    }
    public void add(Object m){
          list.offer(m);
    }
    public Object poll(){
          return list.poll();
    }
    public int size(){
          return list.size();
    }
    public Object get(int index)
    {
          return list.get(index);
    }
    public boolean contains(Object o){
          return list.contains(o);
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值