Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

llend of getinput2 method /Wend of class/program 12. Instances of the Card class

ID: 3754714 • Letter: L

Question

llend of getinput2 method /Wend of class/program 12. Instances of the Card class shown below represent standard playing cards. Each card has a rank and a suit. The ranks are 2, 3, 4, 5, 6, 7,8,9, 10, jack, queen, king, and ace, which are represented by the numbers 0 through 12, respectively. The suits are clubs, diamonds, hearts, and spades, which are represented by 0, 1,2, and 3, respectively. Your job is to complete the definition of the class by filling in the body of each method. (Hint: All methods are short and simple.) (21 pts). public class Card private int rank; /a number between 0 and 12 private int suit; I/a number between 0 and 3 private statice final String RANKS "23456789TJQKA" private static final String SUITS "CDHS"; Initializes this card to contain rank r and suit s (4 pts public Card(int r, int s)

Explanation / Answer

import java.util.Random; public class Card { private int rank; private int suit; private static final String RANKS = "23456789TJQKA"; private static final String SUITS = "CDHS"; public Card(int r, int s) { rank = r; suit = s; } public int getRank() { return rank; } public int getSuit() { return suit; } public String toString() { return RANKS.charAt(rank) + "" + SUITS.charAt(suit); } public static Card pickRandom() { Random random = new Random(); return new Card(random.nextInt(13), random.nextInt(4)); } }