Java问题 高分求解!!!!!!

[复制链接]
查看11 | 回复1 | 2010-3-4 20:57:44 | 显示全部楼层 |阅读模式
import java.util.ArrayList;import java.util.Collections;import java.util.List;public class Test {
public static void main(String[] args) {
// 创建一幅牌
DeckOfCards cards = new DeckOfCards();
// 未洗牌前,先看看牌是什么样子的
cards.deal();
// 洗牌
cards.shuffle();
// 洗牌后,先看看牌是什么样子的
cards.deal();
}}class Card {
// 这里用整型来代表花色与点数,point(0-12代表点数A-K),suit(0-3代表花色),表示再说
private int point, suit;
public Card(int point, int suit) {
this.point = point;
this.suit = suit;
}
// 点数对应的英文
public static final String[] POINTS = { "ace", "deuce", "three", "four",
"five", "six", "severn", "eight", "nine", "ten", "jack", "queen",
"king" };
// 花色对应的英文
public static final String[] SUITS = { "heart", "spades", "diamonds",
"club" }; // 0123分别对应红黑方梅
// 打印出这张扑克,包括花色与点数
public String toString() {
return SUITS[suit] + " " + POINTS[point];
}}// 一幅牌class DeckOfCards {
List cards = new ArrayList();
public DeckOfCards() {
// 创建52张牌
for (int suit = 0; suit < 4; suit++) {// 花色
for (int point = 0; point < 13; point++) {
cards.add(new Card(point, suit));
}
}
}
/**
* 洗牌
*/
public void shuffle() {
Collections.shuffle(cards);
}
/**
* 发牌,其实就是显示
*/
public void deal() {
for (Card card : cards) {
System.out.println(card);
}
}}
回复

使用道具 举报

千问 | 2010-3-4 20:57:44 | 显示全部楼层
public class Card { public Card() { } public Card(String pointStr,String style){this.pointStr=pointStr;this.style=style; } private String pointStr;private String style; //样式 public String getPointStr() {return pointStr; } public void setPointStr(String pointStr) {this.pointStr = pointStr; } public String getStyle() {return style; } public void setStyle(String style) {this.style = style; }public String toString() {return this.style+","+this.pointStr; } }public class DeckOfCards { public DeckOfCards() { } public static void main(String[] args){String[] points=new String[]{"Ace","Deuce","Three","Four","Five","Six","Seven","Eight","Nine","Ten", "Jack","Queen","King"}; String[] styles=new String[]{"Hearts","Diamonds","Clubs","Spades"};Card[] card=new Card[52];for(int i=0;i<styles.length;i++){ for(int j=0;j<points.length;j++){
card[13*i+j]=new Card(points[j],styles); }}for(int i=0;i<card.length;i++){ System.out.println(card);} }}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行