这个java代码应该可以工作,但它给出了一个错误:
no main classes found.
我知道没有专门的“public static void main”类,但我这里不需要,对吧?我正在使用 NetBeans IDE。
public enum Face
{
TWO(2),
THREE(3),
FOUR(4),
FIVE(5),
SIX(6),
SEVEN(7),
EIGHT(8),
NINE(9),
TEN(10),
JACK(11),
QUEEN(12),
KING(13),
ACE(14);
private int cardValue;
private Face (int value)
{
this.cardValue = value;
}
public int getCardValue() {
return cardValue;
}
}
public enum Suit
{
HEARTS,
SPADES,
CLUBS,
DIAMONDS;
}
public class Card
{
private Suit suit;
private Face cardValue;
public Card (Face cardValue, Suit suit)
{
this.cardValue = cardValue;
this.suit = suit;
}
public Suit getSuit()
{
return suit;
}
public void setSuit(Suit suit)
{
this.suit = suit;
}
public Face getCardValue()
{
return cardValue;
}
public void setCardValue(Face cardValue)
{
this.cardValue = cardValue;
}
}
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
public class DeckofCards
{
private ArrayList<Card> deck;
public DeckofCards ()
{
this.deck = new ArrayList<>();
for (int i=0; i<13; i++)
{
Face value = Face.values()[i];
for (int j=0; j<4; j++)
{
Card card = new Card(value, Suit.values()[j]);
this.deck.add(card);
}
}
Collections.shuffle(deck);
Iterator<Card> cardIterator = deck.iterator();
while (cardIterator.hasNext())
{
Card aCard = cardIterator.next();
System.out.println(aCard.getCardValue() + " of " + aCard.getSuit());
}
}
}