Java

OOP GUIDE / WORK

 

CARD CLASS

 

Topics

  • Instance variables
  • Constructors

 

 

TASK – PART 1 – CARD CLASS


Create a Card class that will represent a playing card like the ones in the image below.

 

Giant Playing Cards | Olympic Party Hire

 

The class needs to store the value of the card (integer) and the suit of the card (String).  The class needs to have a constructor that gets both the value and suit as parameters in order to initialize the data fields.


Notice that it is not obvious what is meant by value and suit.  Value should hold a number from 1 to 13 (Ace to King) and suit should hold one of “hearts”, “diamonds”, “clubs” or “spades”.  For now, you have to assume that the class will be used as expected.

 

TASK – PART 2 – TESTING THE CARD CLASS


In the CardTester class, inside the main function, create the following cards:

 

4 of clubs

10 of hearts

12 of diamonds (also known as Queen of diamonds)