You can provide an initial capacity for how many card you are going to have get all possible value from the enums for Suit and Ranks * These comments will be shown in IDEs and an HTML page can be auto-generated from them. * Try to use Java Doc syntax to like this to comment on methods. There are some changes required due to the previous changes I've made but this is essentially your Deck with the change described above. The remove() method of an ArrayList does return the removed value by default so use that.Īlso, that's maybe splitting hairs, but I think you should rename deal() to drawTop() as dealing in the real-world involves first drawing a card then giving it to a player, who then accepts that card and puts it in his hand. In your implementation you just remove the card on the top of the deck but you don't return it, so you're essentially just wiping a card from memory and it is lost and cannot be played in the game. But there is a issue with your method deal() which hinders you from knowing which card was drawn. This war actually quite well designed by you as a deck is just a collection of cards. Return rank.toString() + "-" + suit.toString() value of a card is not going to change, so we can make it final Designing it this way will also help you staying on top of your program because your design will be easier to comprehend. Your class Card is a somewhat simplified model of the real-world card so it should have the properties of a real-world card. A card certainly does not hold all values of possible ranks and suits, but only has one rank and one suit. The problem with your implementation of the card is that you had an array of all possible values for ranks and suits in every card. With it's rank it will automatically have a value assigned as well now. A card only needs a Suit and a Rank and that's it. This has some nice benefits for the Card class. * display String displayed to represent this rank * Each rank has a value and a String which determines how the rank is displayed in the console. the value is determined only by rank so assign the value here! Here how I would implement Rank and Suit. Always keep in mind enums are just special classes so they can have attributes as well. Another thing to consider for both, ranks and suits, is there is only a limited set of allowed and well-defined values which is far smaller than the range of values an int or String could take so I would propose you use an enum to type those values. Additionally, it will not be changing over time, that is why you should keep the value closely coupled to the rank. In your design a card has a value attribute but if you think about it, a card's value in BlackJack is determined by its rank and its rank only. This is part of the reason why you find it hard to assign a value to the card that is drawn. (playingDeck) //printing out card 2Īlthough you are generally on the right track, your implementation has some design decisions that you should reconsider. PlayingDeck.remove() //removing card 2 from deck PlayingDeck.remove() //removing card 1 from deck public class Gameĭeck playingDeck = new Deck() //creating deck object But here is what I have to help to know if I printed out the card with a value or not. My hope was to get the deck built, deal a card and get the value and then I'd start building the main method. I do not have an official blackjackgame class with a main method as of yet. Public String toString() //display the choosen card Public Deck() //building deck with 52 cards Can anyone provide any direction for me? Any help would be greatly appreciated!īelow are my Card and Deck class: public class Card Where I am at a stand still is assigning a value to the card that was pulled. I have built my deck, shuffled it and dealt a card. Our major project is to build and run a blackjack program using java. I have zero programming experience other than the bit I've had in this class. I am working on building a blackjack game for my first programming class.
0 Comments
Leave a Reply. |