Advertisement
Guest User

please explain this code

a guest
Feb 27th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. public class Card
  2. {
  3.     // instance variables
  4.     private int value;
  5.     private String suit;
  6.  
  7.     /**
  8.      * parameterized Card constructor
  9.      * gets called when an object of the Card class is instantiated sending a number
  10.      * as an argument - it determines the value and suit of the card based upon the
  11.      * number received
  12.      * @param num a number that gets converted to a value between 1 and 13
  13.      * and one of the four suits (clubs, diamonds, hearts, or spades)
  14.      */
  15.     public Card(int num)
  16.     {
  17.         int suitNumber;
  18.         value = num % 13;
  19.         if (value == 0)
  20.             value = 13;
  21.         suitNumber = num / 13;
  22.         if (suitNumber == 0)
  23.             suit = new String("clubs");
  24.         else if (suitNumber == 1)
  25.             suit = new String("diamonds");
  26.         else if (suitNumber == 2)
  27.             suit = new String("hearts");
  28.         else if (suitNumber == 3)
  29.             suit = new String("spades");
  30.         else
  31.             suit = new String("ERROR");
  32.     }
  33.  
  34.     /**
  35.      * getValue method - returns what's stored in the instance variable value
  36.      * @return the state of the instance variable value
  37.      */
  38.     public int getValue()
  39.     {
  40.         return value;
  41.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement