我沒有輸出,也不知道該從哪裏出發。一副撲克牌使用方法和多個類別
設計並實現一個名爲Card的類,它代表一張標準撲克牌。每張卡片都有西裝和麪值。然後,創建一個驅動程序類,將Card類的52個對象存儲到數組中。包括洗牌的方法,交易一張卡片並報告卡片中留下的卡片數量。洗牌方法應該假設一個完整的套牌。你的主要方法應該從洗牌平臺處理每張牌,打印每張牌(套裝和麪值)。
這是我到目前爲止有:
import java.util.Random;
public class card {
public static void main(String[] args) {}
public class deck {
int[] deck = new int[52];
String[] suits = {"Spades", "Hearts", "Diamonds", "Clubs"};
String[] ranks = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"};
public void create() {//initialize cards
for (int i = 0; i < deck.length; i++) deck[i] = i;
}
public void shuffle() {//deck shuffle
for (int i = 0; i < deck.length; i++) {
int index = (int) (Math.random() * deck.length);
int temp = deck[i];
deck[i] = deck[index];
deck[index] = temp;
}
//display all the cards!
for (int i = 0; i < deck.length; i++)
{
String suit = suits[deck[i]/13];
String rank = ranks[deck[i] % 13];
System.out.println("Card number " + deck[i] + ": " + rank + " of " + suit);
}
}
}
}
不相關,但使用一致的縮進和刪除僞造的空白使代碼更容易閱讀和推理。 –