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");
}
}
}
}
洗扑克牌
最新推荐文章于 2024-10-06 20:16:20 发布