Normally ACE is before 2. Need help coding making sure ACE is ranked higher than
ID: 3782762 • Letter: N
Question
Normally ACE is before 2. Need help coding making sure ACE is ranked higher than KING.Thank you Firstly, for this week Lab let them build a card class that is made up of two variables a rank (int) and a suit (string). This class must have at least two constructors one default that will create a card that is Ace (represented by 14) of Spades and the other constructor must accept an int and a String as parameters. They must also include getters and setters. The must also have a print method that will print a card for example if a card is 11 of hearts it must print Jack of Hearts. CI s new car
Explanation / Answer
package javacards;
public class Card
{
private int rank, suit;
private static String[] suits = { "hearts", "spades", "diamonds", "clubs" };
private static String[] ranks = { "Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King" };
Card(int suit, int rank)
{
this.rank=rank;
this.suit=suit;
}
public @Override String toString()
{
return ranks[rank] + " of " + suits[suit];
}
public int getRank() {
return rank;
}
public int getSuit() {
return suit;
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.