Create a Java class in BlueJ called Card . The class should have the following:
ID: 3749359 • Letter: C
Question
Create a Java class in BlueJ called Card. The class should have the following:
A field called rank which stores the value of the card. The integer values 1 through 10 will denote the cards Ace through Ten. Jack, Queen and King will be stored as the integer values 11 through 13 respectively.
A field called suit which stores the suit of the card. The values 'C', 'D', 'H', and 'S' will denote the suits Club, Diamond, Heart, and Spade respectively.
A method called getSuit which returns the suit of a card object.
A method called getRank which returns the rank of a card object.
A method called setSuit which sets the suit of a card object to a given value.
A method called setRank which sets the rank of a card object to a given value.
A method called setCard which sets both the suit and rank of a card object to specified values.
Explanation / Answer
public class Card { private int rank; private char suit; public int getRank() { return rank; } public char getSuit() { return suit; } public void setRank(int rank) { this.rank = rank; } public void setSuit(char suit) { this.suit = suit; } public void setCard(int rank, char suit) { setSuit(suit); setRank(rank); } }