本文介绍了卡片程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我有作业,因为明天一直试图做家庭作业整周和没有发生的事情

真正开始强调我不明白该计划的意图或如何使用三个班级


程序

本周你要编写三个类:Card.java,Deck.java和DeckTester.java。每个课程的规格如下:


Card.Java

这是一个代表扑克牌的简单课程。




卡片有两个属性:rank是一个代表卡片价值的String。它取值?ACE,?2?,?3?,?,?JACK?,?QUEEN?,?KING ?;适合使用值的字符串?SPADES?,?DIAMONDS?,?CLUBS?,?HEARTS?。


该类有一个构造函数,它带有两个参数:第一个是int表示1到13范围内的等级;第二个代表诉讼的字符串。构造函数必须将int转换为适当的String值。


另外有两种方法分别返回套装和等级的字符串表示。


Deck.java

这个类代表一副扑克牌。



这个类有两个属性:一个数组卡持有甲板的52张牌;保存卡片中卡片数量的int(此作业中不使用此属性,但稍后可能会使用);


提供类的骨架。您必须完成缺少的组件。这个文件可以在Blackboard上找到,带有家庭作业规范。


DeckTester.java

这个类包含主要方法。其目的是让您证明您的甲板课程按预期工作。特别需要:

?确认构造函数是否正常工作

?确认shuffle正常工作。

标记


标准标准

1 Card.java:构造函数

1 Card.java:0.5为每个getter方法

2 Deck.java:构造函数

2 Deck.java:shuffle()

1 Deck.java:toString()

3显示deck.java是正确的


Deck.java骨架


/ **

*此课程代表一副52张扑克牌。

*

* @author Ian Bradley

* @version 6/2/07

* /

公共舱甲板

{

private Card [] deck = COMPLETE;

private int numberOfCards;


/ **

*创建一副甲板52张扑克牌

*套牌按顺序设置SPADES,DIAMONDS,CLUBS,HEARTS

* /

公共甲板()

{

String [] suit = {" SPADES"," DIAMONDS"," CLUB S",HEARTS"};

// FOR EACH SUIT

//每个级别

//安装甲板元素作为一张卡

numberOfCards = 52;

}


/ **

*洗牌卡片。

*

* /

public void shuffle()

{

卡片临时费用;

//循环通过卡片中的每张卡片并用随机卡片交换它。

为每张卡片中的卡片

{

int rand =(int)(Math.random()* 52);

//拿着当前的卡......

//并使用兰德卡交换它......

}

}


/ **

*以字符串形式返回牌组的表示

*每行一张牌

* @retle甲板作为一个字符串

* /

public String toString()

{

String deckString ="" ;;

//构建字符串

返回deckString;

}

}

hi i have homework due tomorrow been trying to do java homework all week and nothings happening
really starting to stress out i dont understand what the program is meant to do or how to use three classes

The program
This week you are going to write three classes: Card.java, Deck.java and DeckTester.java. The specification for each class is given below.

Card.Java
This is a simple class that represents a playing card.




Card has two attributes: rank which is a String that represents the value of a card. It takes the values ?ACE,?2?,?3?,?,?JACK?,?QUEEN?,?KING?; suit a String which takes the values ?SPADES?,?DIAMONDS?,?CLUBS?,?HEARTS?.

The class has a single constructor which takes two parameters: the first is an int that represents the rank in the range 1 to 13; the second a String representing the suit. The constructor must convert the int into an appropriate String value.

Additionally there are two methods that return String representations of the suit and rank respectively.

Deck.java
This class represents a deck of playing cards.



This class has two attributes: an array of Cards holding the 52 cards of the deck; an int that holds the number of cards in the deck, (this attribute is not used in this homework but may be used later);

A skeleton of the class is provided. You have to complete the missing components. This file can be found on Blackboard with the homework specification.

DeckTester.java
This class contains the main method. Its purpose is to allow you to demonstrate that your deck class works as anticipated. In particular you need to:
?Confirm that the constructor works correctly
?Confirm that shuffle works correctly.
Marking

MarkCriteria
1Card.java : Constructor
1Card.java : 0.5 for each getter method
2Deck.java : Constructor
2Deck.java : shuffle()
1Deck.java : toString()
3Showing deck.java is correct


Deck.java skeleton

/**
* This class represents a deck of 52 playing cards.
*
* @author Ian Bradley
* @version 6/2/07
*/
public class Deck
{
private Card [] deck = COMPLETE;
private int numberOfCards ;

/**
* Creates a deck of 52 playing cards
* The deck is set up in the order SPADES, DIAMONDS, CLUBS,HEARTS
*/
public Deck()
{
String [] suits = {"SPADES","DIAMONDS","CLUBS","HEARTS"};
//FOR EACH SUIT
//FOR EACH RANK
//INSTANTIATE A ELEMENT OF deck AS A CARD
numberOfCards = 52;
}

/**
* shuffles the deck of cards.
*
*/
public void shuffle()
{
Card temp;
//loop through each card in the deck and swap it with some random card.
FOR EACH CARD IN THE DECK
{
int rand = (int)(Math.random()*52);
//TAKE THE CURRENT CARD...
//AND SWAP IT WITH THE RAND CARD...
}
}

/**
* Returns a representation of the deck as a string
* one card per line
* @return the deck as a String
*/
public String toString()
{
String deckString = "";
//BUILD THE STRING
return deckString;
}
}

推荐答案




这篇关于卡片程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 23:16