Answered step by step
Verified Expert Solution
Question
1 Approved Answer
test case: public void testHandSequenceLength ( ) { deck = new Deck ( ) ; hand 1 = new Hand ( Amina ,
test case:
public void testHandSequenceLength
deck new Deck;
hand new HandAmina deck;
assertEquals handsequenceLength;
deck new Deck;
hand new HandNina deck;
assertEquals handsequenceLength;
ArrayList cards new ArrayList;
cards.addnew Cardnew RankTwo new SuitHeartsH "red", ;
cards.addnew Cardnew RankFour new SuitHeartsH "red", ;
cards.addnew Cardnew RankKingK new SuitHeartsH "red", ;
cards.addnew Cardnew RankEight new SuitHeartsH "red", ;
cards.addnew Cardnew RankThree new SuitClubsC "black", ;
cards.addnew Cardnew RankQueenQ new SuitHeartsH "red", ;
hand new HandAmina cards;
assertEquals handsequenceLength;
cards.addnew Cardnew RankAceA new SuitClubsC "Black", ;
hand new HandAmina cards;
assertEquals handsequenceLength;
cards.addnew Cardnew RankJackJ new SuitHeartsH "red", ;
cards.addnew Cardnew RankTenX new SuitClubsC "black", ;
cards.addnew Cardnew RankNine new SuitHeartsH "red", ;
hand new HandAmina cards;
assertEquals handsequenceLength;
currentMethodName new ObjectgetClassgetEnclosingMethodgetName;
my code isn't passing the test cases. the question says to return the length of the longest "sequence: of cards in the hand.
public int sequenceLength
if cardsInHandisEmpty
return ;
arrange;
ArrayList ranks new ArrayList;
for Card card : cardsInHand
ranks.addcardrank.value;
if cardrank.value
ranks.add;
ranks.sortnull;
int maxLength ;
int currentLength ;
for int i ; i ranks.size; i
if ranksgeti ranks.geti
currentLength;
else if ranksgeti ranks.geti
maxLength Math.maxmaxLength currentLength;
currentLength ;
maxLength Math.maxmaxLength currentLength;
return maxLength;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started