我似乎無法弄清楚如何創建這種簡單的撲克牌。如果有人可以請示例說明「你的代碼放在這裏」部分,這會非常有幫助。創建一副撲克牌
通過發生在以下主要方法註釋進入合適的代碼,創建一副撲克牌:
public class Card
{
private String mySuit;
private int myValue;
public Card(String suit, int value)
{
mySuit = suit;
myValue = value;
}
public String name()
{
String[] cardNames =
{
"Deuce", "Three", "Four", "Five",
"Six", "Seven", "Eight", "Nine", "Ten",
"Jack", "Queen", "King", "Ace"
};
return cardNames[ myValue - 2 ] + " of " + mySuit;
}
}
public class MainClass
{
public static void main(String[] args)
{
Card[] deck = new Card[ 52 ];
String[] suits = { "spades", "hearts", "diamonds", "clubs" };
int i;
for (i = 0 ; i < suits.length ; i++)
{
for (int k = 2 ; k <= 14 ; k++)
{
// your code goes here
}
}
for (Card card : deck)
System.out.println(card.name());
}
}
看起來你已經複製並粘貼了你的家庭作業。你試過什麼了? – digitaljoel
'Deuce'?這不是我見過的任何卡組。 – Quill
賭場撲克經銷商被教導使用術語「deuce」和「trey」而不是「two」和「three」。 –