Java

OOP GUIDE / WORK

 

CARD CLASS SOLUTIONS

 

 

TASK – PART 1 – CARD CLASS

 

Here is my solution:


public
class Card

{

     public int value;     //1 to 13 (representing A to K)

     public String suit;   //"hearts", "diamonds", "spades" or "clubs"

    

     public Card(int tvalue, String tsuit)

     {

           value = tvalue;

           suit = tsuit;

     }

}

 

 

 

TASK – PART 2 – TESTING THE CARD CLASS


Here is my solution:

 


public
class Question03

{

     public static void main(String[] args)

     {

           //Create the cards.

           Card c1 = new Card(4, "clubs");

           Card c2 = new Card(10, "hearts");

           Card c3 = new Card(12, "diamonds");  //Queen

          

           //Output the card information to screen.

           System.out.println(c1.value + " of " + c1.suit);

           System.out.println(c2.value + " of " + c2.suit);

           System.out.println(c3.value + " of " + c3.suit);

     }

}