1public class Card { 2 3 private int suit; 4 private int face; 5 6 public Card() {} 7 8 /** 9 * Constructs a card object with specified suit and face10 * @param suit -- Suit of card (int)11 * @param face -- Face of card (int)12 */13 14 public Card(int suit, int face) {15 this.suit = suit;16 this.face = face;17 }18 19 public int getSuit() {20 return this.suit;21 }22 public int getFace() {23 return this.face;24 }25 public String toString() {26 String output = "";27 //add switch case that sets output to the face of the card28 switch(this.getFace()) {29 case 1:30 output = "Ace";31 break; 32 case 11:33 output = "Jack";34 break;35 case 12:36 output = "Queen";37 break;38 case 13:39 output = "King";40 break;41 default:42 output = Integer.toString(this.getFace());43 }44 //add another switch case that adds " of " and the suit of the card45 switch(this.getSuit()){46 case 1:47 output += " of Spades";48 break;49 case 2:50 output += " of Hearts";51 break;52 case 3:53 output += " of Diamonds";54 break;55 case 4:56 output += " of Clubs";57 break;58 }5960 return output;61 }62}
1import java.util.ArrayList;
2public class Player { 3 4 private ArrayList<Card> hand = new ArrayList<Card>(); 5 6 private int chipsAmount; 7 private int betAmount; 8 private String name; 91011 public Player() {12 chipsAmount = 100;13 }14 public Player(int amount, String name) {15 chipsAmount = amount;16 this.name = name;17 }1819 public int getChipsAmount() {20 return chipsAmount;21 }22 public void setChipsAmount(int amount) {23 chipsAmount = amount;24 }25 public int getBet() {26 return betAmount;27 }28 public void setBet(int amount) {29 betAmount = amount;30 }31 public ArrayList<Card> getHand() {32 return hand;33 }34 public void clearHand() {35 hand.clear();36 }37 public void addCard(Card card) {38 hand.add(card);39 }40 public int getHandAmount(Card card) {41 int amount = 0;42 for(Card cardHand: this.getHand()){43 amount = amount + cardHand.getFace();44 }45 return amount;46 }47 public String getName() {48 return name;49 }50}
1import java.util.ArrayList;
2import java.util.Collections;
3public class Deck { 4 private ArrayList<Card> cards = new ArrayList<Card>(); 5 6 /** */ 7 public Deck() { 8 for (int j = 0; j < 13; j++) { 9 for (int i = 0; i < 4; i++) {10 cards.add(new Card(i + 1, j + 1));11 }12 }13 }1415 public void shuffle() {16 Collections.shuffle(cards);17 }18 public ArrayList<Card> getDeck() {19 return cards;20 }21 /**22 * Gets specifed card based off of index23 * @param cardIndex24 * @return25 * @see #dealTopCard()26 */27 public Card getCard(int cardIndex) {28 return cards.get(cardIndex);29 }30 /**31 * deals the top card of the deck32 * <p>33 * longer description34 * @return The top card in the deck35 */36 public Card dealTopCard() {37 Card tempCard = new Card();38 tempCard = cards.get(0);39 cards.remove(0);40 return tempCard;4142 }4344}
This class does not have any documentation.
Consider adding a documentation comment to explain its use.
While it may seem like the functionality of a class is perfectly obvious, any consumers of your API may not be able to pick up on certain details.
Consider a case where the class given below can be instantiated and provides certain functionalities within each instance in a thread-safe manner, perhaps it is a rest API client.
If there is no documentation comment on the class, it is not immediately obvious that the class is thread safe. Thus, multiple instances of the class may be created to perform operations concurrently, using up both memory as well as OS resources like sockets. If it were known from the beginning that the class were thread safe, the user would not need to create unnecessary extra instances of SomeClass
.
class SomeClass {
// ...
}
Make sure to add useful information regarding the usage or implementation of a particular declaration, so that anything about it which can't be understood from the name or some other cue is correctly conveyed.
/**
* Instances of this class are used to perform xyz action.
*
* This class is thread safe and the same instance can be used over multiple threads.
*/
class SomeClass {
// ...
}
This issue will not be reported for model entity classes. If there is any non-obvious behavior associated with a particular class however, do consider documenting it.