Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Card
- {
- // instance variables
- private int value;
- private String suit;
- /**
- * parameterized Card constructor
- * gets called when an object of the Card class is instantiated sending a number
- * as an argument - it determines the value and suit of the card based upon the
- * number received
- * @param num a number that gets converted to a value between 1 and 13
- * and one of the four suits (clubs, diamonds, hearts, or spades)
- */
- public Card(int num)
- {
- int suitNumber;
- value = num % 13;
- if (value == 0)
- value = 13;
- suitNumber = num / 13;
- if (suitNumber == 0)
- suit = new String("clubs");
- else if (suitNumber == 1)
- suit = new String("diamonds");
- else if (suitNumber == 2)
- suit = new String("hearts");
- else if (suitNumber == 3)
- suit = new String("spades");
- else
- suit = new String("ERROR");
- }
- /**
- * getValue method - returns what's stored in the instance variable value
- * @return the state of the instance variable value
- */
- public int getValue()
- {
- return value;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement