Все, что я получаю, когда запускаю программу, имеет значение null ... и я больше не могу смотреть на это. Я просто не могу найти ошибку ... Может ли кто-то просто дать подсказку, пожалуйста ... Я не знаю, какие другие подробности актуальны.Почему я только возвращаю NULL?
public class Deckofcards
{
public static final int NCARDS = 52;
private card[] deckOfCards; // Contains all 52 cards
private int currentCard; // deal THIS card in deck
public Deckofcards() // Constructor
{
deckOfCards = new card[ NCARDS ];
int i = 0;
for (int suit = card.SPADE; suit <= card.DIAMOND; suit++)
for (int rank = 1; rank <= 13; rank++)
deckOfCards[i++] = new card(suit, rank);
private byte cardSuit;
private byte cardRank;
public card(int suit, int rank)
{
if (rank == 1)
cardRank = 14; // Give Ace the rank 14
else
cardRank = (byte) rank;
cardSuit = (byte) suit;
}
public boolean equals(card x)
{
if (this.cardSuit == x.cardSuit &&
this.cardRank == x.cardRank )
return (true);
else
return (false);
}
public String toString()
{
return (Rank[ cardRank ] + Suit[ cardSuit ]);
}
}
public class Dealer
{
public static void main(String[] args)
{
Deckofcards a;
a = new Deckofcards();
System.out.println(a); // What a new deck look like
System.out.println("Shuffle cards....");
a.shuffle(1000); // Shuffle deck of card "a"
System.out.println(a); // Deck after shuffling
card b;
b = a.deal();
System.out.println("Deal a card: " + b);
b = a.deal();
System.out.println("Deal a card: " + b);
b = a.deal();
System.out.println("Deal a card: " + b);
b = a.deal();
System.out.println("Deal a card: " + b);
b = a.deal();
System.out.println("Deal a card: " + b);
}
}
currentCard = 0;
}
//shuffle(n): shuffle the deck
public void shuffle(int n)
{
int i, j, k;
for (k = 0; k < n; k++)
{
i = (int) (NCARDS * Math.random()); // Pick 2 random cards
j = (int) (NCARDS * Math.random()); // in the deck
//swap these randomly picked cards
card tmp = deckOfCards[i];
deckOfCards[i] = deckOfCards[j];
deckOfCards[j] = tmp;;
}
currentCard = 0; // Reset current card to deal
}
//deal(): deal deckOfCards[currentCard] out
public card deal()
{
if (currentCard < NCARDS)
{
return (deckOfCards[ currentCard++ ]);
}
else
{
System.out.println("Out of cards error");
return (null); // Error;
}
}
public String toString()
{
String s = "";
int k;
k = 0;
for (int i = 0; i < 4; i++)
{
for (int j = 1; j <= 13; j++)
s += (deckOfCards[k++] + " ");
s += "\n";
}
return (s);
}
}
public class card
{
public static final int SPADE = 4;
public static final int HEART = 3;
public static final int CLUB = 2;
public static final int DIAMOND = 1;
private static final String[] Suit = { "*", "d", "c", "h", "s"};
private static final String[] Rank = { "*", "1", "2", "3", "4",
"5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"};
private byte cardSuit;
private byte cardRank;
public card(int suit, int rank)
{
if (rank == 1)
cardRank = 14; // Give Ace the rank 14
else
cardRank = (byte) rank;
cardSuit = (byte) suit;
}
public boolean equals(card x)
{
if (this.cardSuit == x.cardSuit &&
this.cardRank == x.cardRank )
return (true);
else
return (false);
}
public String toString()
{
return (Rank[ cardRank ] + Suit[ cardSuit ]);
}
}
public class Dealer
{
public static void main(String[] args)
{
Deckofcards a;
a = new Deckofcards();
System.out.println(a); // What a new deck look like
System.out.println("Shuffle cards....");
a.shuffle(1000); // Shuffle deck of card "a"
System.out.println(a); // Deck after shuffling
card b;
b = a.deal();
System.out.println("Deal a card: " + b);
b = a.deal();
System.out.println("Deal a card: " + b);
b = a.deal();
System.out.println("Deal a card: " + b);
b = a.deal();
System.out.println("Deal a card: " + b);
b = a.deal();
System.out.println("Deal a card: " + b);
}
}
Вот что я получаю.
null null null null null null null null null null null null null
нуль нуль нуль нуль нуль нуль нуль нуль нуль нуль нуль нуль нуль нуль нуль нуль нуль нуль нуль нуль нуль нуль нуль нуль нуль нуль нуль нуль нуль нуль нуль нуль нуль нуль нуль нуль нуль нуль нуль
Shuffle cards .... null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null л
Deal карты: нулевой Deal карты: нулевой Deal карты: нулевой Deal карты: нулевой Deal карты: нулевой
Таким образом, вы ожидаете, что мы прочитали 200 строк кода, чтобы найти 'null' где-нибудь ... –
Пожалуйста [править] Ваш вопрос, чтобы включить какой метод (ы) является (являются) возвращение нулевой, и * * исправьте код вдавливания **. –
Все они возвращают null. Я опубликую, как выглядят мои результаты. – Savage99