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

Need help with this program please. Will upvote. Source code for Card class is b

ID: 3917555 • Letter: N

Question

Need help with this program please. Will upvote. Source code for Card class is below! include comments when possible for clarification.

Student Number: 101046891

public abstract class Card implements Comparable<Card>{

  

/* handy arrays for ranks and suits */

/* do NOT change these */

public final static String[] RANKS = { "None", "Joker",

"2", "3", "4", "5", "6", "7", "8", "9", "10",

"Jack", "Queen", "King", "Ace"};

public final static String[] SUITS = { "Diamonds",

"Clubs", "Hearts", "Spades", "NONE"};

  

  

  

/** creates a card with specified suit and rank

*

* @param suit is the suit of the card (must be a string from Card.SUITS)

* @param rank is the rank of the card (must be a string from Card.RANKS)

*/

public Card(String suit, String rank){

// add code here if needed

}

  

/** the numerical representation of the rank of the current card

* <p>

* ranks have the numerical values

* Joker = 1,  

* 2 = 2, 3 = 3, ..., 10 = 10

* Jack = 11, Queen = 12, King = 13, Ace = 14

*  

* @return the numerical rank of this card

*/

public abstract int getRank();

/** the string representation of the rank of the current card

*

* @return the string representation of the rank of this card (must be a string from Card.RANKS)

*/

public abstract String getRankString();

  

/** the suit of the current card

*

* @return the suit of this card (must be a string from Card.SUITS)

*/

public abstract String getSuit();

  

  

  

@Override

public final String toString(){

// outputs a string representation of a card object

int r = getRank();

if( r >= 2 && r <= 14 ){

return r + getSuit().substring(0,1);

}

if (r == 1){

return "J";

}

return "invalid card";

}

  

}

Explanation / Answer

abstract class Card implements Comparable { /* handy arrays for ranks and suits */ /* do NOT change these */ public final static String[] RANKS = {"None", "Joker", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace"}; public final static String[] SUITS = {"Diamonds", "Clubs", "Hearts", "Spades", "NONE"}; protected String suit, rank; // hold suit and string for the card /** * creates a card with specified suit and rank * * @param suit is the suit of the card (must be a string from Card.SUITS) * @param rank is the rank of the card (must be a string from Card.RANKS) */ public Card(String suit, String rank) { setSuit(suit, rank); //set suit of the card if it's joker to SUITS[4] else stated by user this.rank = rank; // set rank of the card to given rank } private void setSuit(String suit, String rank) { // sets the suit for the card if joker then set it to SUITS[4] if (rank == RANKS[1]) this.suit = SUITS[4]; this.suit = suit; } /** * the numerical representation of the rank of the current card *

*

*

* ranks have the numerical values *

* Joker = 1, *

* 2 = 2, 3 = 3, ..., 10 = 10 *

* Jack = 11, Queen = 12, King = 13, Ace = 14 * * @return the numerical rank of this card */ public abstract int getRank(); /** * the string representation of the rank of the current card * * @return the string representation of the rank of this card (must be a string from Card.RANKS) */ public abstract String getRankString(); /** * the suit of the current card * * @return the suit of this card (must be a string from Card.SUITS) */ public abstract String getSuit(); public abstract int getSuitInt(); @Override public final String toString() { // outputs a string representation of a card object int r = getRank(); if (r >= 2 && r