Campbell Ritchie wrote:Apart from the fact that you have the faces out of order, with the Ace below the Deuce
All right. But does a card have any value at all, apart from a game rule?Stephan van Hulst wrote:. . . There is no standard order that says that the Ace comes before the Deuce, or after the King.
Didn't notice that.. . . the OP wrote "Joker" instead of "Jack".
Ana Yo wrote:Can you show me how to code it? I'm not sure how to do it, that's why I came to this website.
Yes, and no. You are declaring the same thing twice. Haven't they told you about declaring the same thing twice? In the second instance it is a local variable which goes out of scope before you ever do anything with it. I would make the changes shown below:-Ana Yo wrote:Is the logic error that I have two of the exact same lines and I should delete it?
I would also check the formatting; the excess empty lines make the code harder to read. I would also declare deck as List<Card>.public class StandardDeck
{
ArrayList<Card> deck= new ArrayList<Card>(52);
/*Pre-condition: none
*Post-condition: An ArrayList of objects of type Card will be created
*/
public StandardDeck()
{
ArrayList<Card>deck = new ArrayList<Card>(52);
buildDeck();
}
// ...
Thank you; I hadn't noticed that. In which case I would have to change the constructor to read:-. . . and buildDeck() has to change its return type.Dave Tolls wrote:. . . part of the comment (which I assume is the requirements) for the buildDeck method . . .
Ana Yo wrote:Hi there, I just started learning about ArrayLists and I am trying to implement a deck of cards. The instructions are:
/*Pre-condition: none
*Post-condition: A new ArrayList of cards will be created with 52 cards.
*There will be 4 suits with 13 cards each.
*/
This is what I have so far:
I don't know if I should add more code or not.
Michael Sims
Campbell Ritchie wrote:I am not sure that will work, because OP is required to produce a List<Card>. I don't know why she said anything about a List<Integer>.
Michael Sims
Michael Sims
Michael Sims
Don't worry about it.Michael D Sims wrote:. . . . ... my bad.
What are you saying? I thought you said that Santa gave you that. And this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|