165k views
4 votes
Create a Card class that represents a playing card. It should have an int instance variable named rank and a char variable named suit. Give it a constructor with two parameters for initializing the two instance variables and give it a getSuit() method and a getRank() method that return the values of the two instance variables. Then create a CardTester class with a main method that creates five Cards that make up a full house (that is, three of the cards have the same rank and the other two cards have the same rank) and prints out the ranks and suits of the five Cards using the getSuit() and getRank) methods

User Rommex
by
4.3k points

1 Answer

3 votes

Answer:

Step-by-step explanation:

The following code is written in Java. It creates the Card class and then uses it to create a full house and print out the rank and suit of every card in that hand.

class Card {

int rank;

char suit;

public Card(int rank, char suit) {

this.rank = rank;

this.suit = suit;

}

public int getRank() {

return rank;

}

public char getSuit() {

return suit;

}

}

class CardTester {

public static void main(String[] args) {

Card card1 = new Card(3, '♥');

Card card2 = new Card(3, '♠');

Card card3 = new Card(3, '♦');

Card card4 = new Card(2, '♦');

Card card5 = new Card(2, '♣');

System.out.println("Card 1: " + card1.getRank() + " of " + card1.getSuit());

System.out.println("Card 2: " + card2.getRank() + " of " + card2.getSuit());

System.out.println("Card 3: " + card3.getRank() + " of " + card3.getSuit());

System.out.println("Card 4: " + card4.getRank() + " of " + card4.getSuit());

System.out.println("Card 5: " + card5.getRank() + " of " + card5.getSuit());

}

}

Create a Card class that represents a playing card. It should have an int instance-example-1
User Susheel Karam
by
3.9k points