Difference between revisions of "Card class lab assignment"

From WLCS
Line 1: Line 1:
 
== Card class ==
 
== Card class ==
* Attributes
+
=== Attributes ===
** String suit
+
* String suit
*** Possible suits will be: Diamonds, Clubs, Hearts, Spades
+
** Possible suits will be: Diamonds, Clubs, Hearts, Spades
** String name
+
* String name
*** 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace
+
** 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace
* Constructor
+
=== Constructor(s) ===
** Card() - default constructor
+
* Card() - default constructor
** Card(String name, String suit) - specific constructor
+
* Card(String name, String suit) - specific constructor
*** Sets the internal attributes to the same as the parameters
+
** Sets the internal attributes to the same as the parameters
** Card(int num)
+
* Card(int num)
*** Creates a card name and suit from a number
+
** Creates a card name and suit from a number
*** If num mod 4 == 0, then make suit Diamonds
+
** If num mod 4 == 0, then make suit Diamonds
*** If num mod 4 == 1, then make suit Clubs
+
** If num mod 4 == 1, then make suit Clubs
*** If num mod 4 == 2, then make suit Hearts
+
** If num mod 4 == 2, then make suit Hearts
*** If num mod 4 == 3, then make suit Spades
+
** If num mod 4 == 3, then make suit Spades
*** If num mode 13 == 0, then make name 2
+
** If num mode 13 == 0, then make name 2
*** If num mode 13 == 1, then make name 3
+
** If num mode 13 == 1, then make name 3
*** If num mode 13 == 2, then make name 4
+
** If num mode 13 == 2, then make name 4
*** ...do the rest of the name cases up to 10 (Hint, there's actually a much simpler math trick that you can use to do this portion)
+
** ...do the rest of the name cases up to 10 (Hint, there's actually a much simpler math trick that you can use to do this portion)
* Methods
+
=== Methods ===
** String getSuit()
+
* String getSuit()
** void setSuit()
+
* void setSuit()
** String getName()
+
* String getName()
** void setName()
+
* void setName()
** int getValue()
+
* int getValue()
*** returns the numerical value of the card
+
** returns the numerical value of the card
*** 2 is lowest, Jack=11, Queen=12, King=13, Ace=14 (we'll treat Ace as always high)
+
** 2 is lowest, Jack=11, Queen=12, King=13, Ace=14 (we'll treat Ace as always high)
** String toString()
+
* String toString()
*** returns the String representation of the card in the form "NAME of SUIT"
+
** returns the String representation of the card in the form "NAME of SUIT"

Revision as of 12:14, 24 October 2018

Card class

Attributes

  • String suit
    • Possible suits will be: Diamonds, Clubs, Hearts, Spades
  • String name
    • 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace

Constructor(s)

  • Card() - default constructor
  • Card(String name, String suit) - specific constructor
    • Sets the internal attributes to the same as the parameters
  • Card(int num)
    • Creates a card name and suit from a number
    • If num mod 4 == 0, then make suit Diamonds
    • If num mod 4 == 1, then make suit Clubs
    • If num mod 4 == 2, then make suit Hearts
    • If num mod 4 == 3, then make suit Spades
    • If num mode 13 == 0, then make name 2
    • If num mode 13 == 1, then make name 3
    • If num mode 13 == 2, then make name 4
    • ...do the rest of the name cases up to 10 (Hint, there's actually a much simpler math trick that you can use to do this portion)

Methods

  • String getSuit()
  • void setSuit()
  • String getName()
  • void setName()
  • int getValue()
    • returns the numerical value of the card
    • 2 is lowest, Jack=11, Queen=12, King=13, Ace=14 (we'll treat Ace as always high)
  • String toString()
    • returns the String representation of the card in the form "NAME of SUIT"