洗扑克牌

package test;

public class Poke {
	private String color;
	private String points;
	public Poke(){
		
	}
	public Poke(String color,String points){
		super();
		this.color = color;
		this.points = points;
	}
	
	public String getColor(){
		return color;
	}
	
	public void setColor(String color){
		this.color = color;
	}
	
	public String getPoints(){
		return points;
	
	}
	
	public void setPoints(String points){
		this.points = points;
	}
	
	public boolean equals(Object obj){
		if(this==obj){
			return true;
		}
		if(obj==null){
			return false;
		}
		if(obj instanceof Poke){
			Poke p =(Poke)obj;
			return(this.color.equals(p.color)&&this.points.equals(p.points));
		}
		return false;
	}
	public String toString(){
		return color+points;
	}

}


package test;

import java.util.ArrayList;
import java.util.Collections;

public class TestPoke {
	public static void main(String[] args) {

		ArrayList<Poke> list = new ArrayList<Poke>();
		String[] colors = { "黑桃", "梅花", "方片", "红桃" };
		String[] points = { "A",  "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" };
		for (int i = 0; i < colors.length; i++) {
			for (int j = 0; j < points.length; j++) {
				list.add(new Poke(colors[i], points[j]));
			}
		}
		for (int i = 0; i < list.size(); i++) {
			System.out.print(list.get(i)+"\t");
			if ((i + 1)% 13 == 0) {
				System.out.print("\n");
			}
		}
		
		Collections.shuffle(list);
		System.out.println("\n洗牌后");
		
		for (int i = 0; i < list.size(); i++) {
			System.out.print(list.get(i)+"\t");
			if ((i + 1)% 13 == 0) {
				System.out.print("\n");
			}
		}

	}
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值