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

Write a Java class called StandardCard that extends the provided Card class. You

ID: 3919194 • Letter: W

Question

Write a Java class called StandardCard that extends the provided Card class. Your class must
have two constructors:


public StandardCard(String rank, String suit)
// purpose: creates a card with given rank and suit
// preconditions: suit must be a string found in Card.SUITS
// rank must be a string found in Card.RANKS
// Note: If the rank is Card.RANKS[15] then any
// valid suit from Card.SUITS can be given
// but the card's suit will be set to Card.SUITS[4]


public StandardCard(int rank, String suit)
// purpose: creates a card with the given rank and suit
// preconditions: suit must be a string found in Card.SUITS
// rank is an integer satisfying 1 <= rank <= 14, where
// 1 for joker, 2 for 2, 3 for 3, .., 10 for 10
// 11 for jack, 12 for queen, 13 for king, 14 for ace
// Note: as with the other constructor, if a joker is created, any valid suit can be passed
// but the card's suit will be set to Card.SUITS[4]
Note that the case of strings is important here. The input strings must be exactly the same as
those found in Card.SUITS or Card.RANKS.


The specifcation for the three abstract methods declared in the Card class are given by:

public int getRank()
// Purpose: Get the current card's rank as an integer
// Output: the rank of the card
// joker -> 1, 2 -> 2, 3 -> 3, ..., 10 -> 10
// jack -> 11, queen -> 12, king -> 13, ace -> 14


public String getRankString()
// Purpose: Get the current card's rank as a string
// Returns the cards's rank as one of the strings in Card.RANKS
// (whichever corresponds to the card)


public String getSuit()
// Purpose: Get the current card's suit
// Returns the card's suit as one of the strings in Card.SUITS
// (whichever corresponds to the card)
Do not change the abstract Card class. You can add any (non-static) attributes and helper
methods that you need for your StandardCard class.

THIS IS THE CODE FOR THE CARD CLASS:

Explanation / Answer

Given below is the code for the question.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you

StandardCard.java
-------

public class StandardCard {
private int rank;
private String suit;
public StandardCard(String rank, String suit)
// purpose: creates a card with given rank and suit
// preconditions: suit must be a string found in Card.SUITS
// rank must be a string found in Card.RANKS
// Note: If the rank is Card.RANKS[1] then any
// valid suit from Card.SUITS can be given
// but the card's suit will be set to Card.SUITS[4]
{
int index = -1;
for(;index < Card.RANKS.length; index++){
if(rank.equals(Card.RANKS[index]))
break;
}

this.rank = index;
if(this.rank == 1)
this.suit = Card.SUITS[4];
else
this.suit = suit;

}


public StandardCard(int rank, String suit)
// purpose: creates a card with the given rank and suit
// preconditions: suit must be a string found in Card.SUITS
// rank is an integer satisfying 1 <= rank <= 14, where
// 1 for joker, 2 for 2, 3 for 3, .., 10 for 10
// 11 for jack, 12 for queen, 13 for king, 14 for ace
// Note: as with the other constructor, if a joker is created, any valid suit can be passed
// but the card's suit will be set to Card.SUITS[4]
{
if(2 <= rank && rank <= 14){
this.rank = rank;
this.suit = suit;
}
else{
this.rank = 1;
this.suit = Card.SUITS[4];
}

}
public int getRank()
// Purpose: Get the current card's rank as an integer
// Output: the rank of the card
// joker -> 1, 2 -> 2, 3 -> 3, ..., 10 -> 10
// jack -> 11, queen -> 12, king -> 13, ace -> 14
{
return rank;
}

public String getRankString()
// Purpose: Get the current card's rank as a string
// Returns the cards's rank as one of the strings in Card.RANKS
// (whichever corresponds to the card)
{
return Card.RANKS[rank];
}

public String getSuit()
// Purpose: Get the current card's suit
// Returns the card's suit as one of the strings in Card.SUITS
// (whichever corresponds to the card)
{
return suit;
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote