At first I thought I would need to create an array but since Im calling upon the Deck class I don't think I should need to create an array, right?
There is a one to one mapping between the methods that you need to write
But then I realised that the assignement instructions say that we are not allowed to modify the Deck class.
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
How do I implement the top method so that it does not remove the top card but instead just return a reference to it?
How does it fail?I am having a bit of trouble with the toString() method. It compiles but isnt passing the unit test.
Unfortunately the cards List of Deck is not accessible and you can't change the Deck class, so using the get(int) method seems to be ruled out. What I suggested before was:
(1) card from the Deck - use nextCard()
(2) put it back - use addAtStart()
(3) return the card to the caller - use return
you are returning too soon. (The compiler would have told you this). Think about introducing a new variable:
public Card top()
{
if(deck.numCardsRemaining() == 0)
{
return null;
}
else
{
return deck.nextCard();
}
deck.addAtStart(Card);
}
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|