0
私はクラスの使用を通してJavaでカードゲームをコーディングしようとしています。メソッドの結果を検証するテストクラスを作成するだけでなく、テストが失敗したかどうかを示すバナーを印刷し、すべてのテストが合格したか失敗したかを確認する最終バナーを出力する必要があります。トランプカードのセットを確認できるテストクラスを作成するにはどうすればよいですか?
トランプクラス(このクラスは、テスターに行われる必要がある)
import java.util.ArrayList;
import java.util.Random;
public class PlayingCards
{
private ArrayList<Card> m_Cards;
private Random gen;
/**
No-arg constructor initializes m_Cards.
Initialize the ArrayList head and the random number generator.
*/
public PlayingCards()
{
m_Cards = new ArrayList<Card>();
gen = new Random();
}
/**
Get the number of cards.
@return number of cards
*/
public int size()
{
return m_Cards.size();
}
/**
Add a card.
*/
public void addCard(Card newCard)
{
m_Cards.add(newCard);
}
/**
Remove a card.
@return null if there are no cards to remove or the instance field is null.
Otherwise, returns a reference to a Card.
*/
public Card removeCard()
{
if (m_Cards.size() == 0)
return null;
else
return m_Cards.remove(0);
}
/**
Shuffle the cards.
This method shuffles the cards.
*/
public void shuffle()
{
if ((m_Cards == null) || (m_Cards.size() < 2))
return;
for (int ii = 0; ii < m_Cards.size(); ++ii)
{
Card a = m_Cards.get(ii);
int swapIndex = gen.nextInt(m_Cards.size());
Card b = m_Cards.get(swapIndex);
// swap the positions of a and b
m_Cards.set(ii, b);
m_Cards.set(swapIndex, a);
}
}
/**
Implement the toString method to show the contents of a
PlayingCards object.
This method relies on Card.toString() method.
*/
@Override
public String toString()
{
String outPut = "";
for (int i = 0; i < m_Cards.size(); i++)
{
outPut += m_Cards.get(i).toString();
outPut += "\n";
}
return outPut;
}
}