Question: Help completing the last two methods for consecutive straight and consecutive straight flush. Java code: public class Card { //INSTANCE VARIABLES private String suit; //Suit

Help completing the last two methods for consecutive straight and consecutive straight flush. Java code: public class Card { //INSTANCE VARIABLES private String suit; //Suit of a card, it goes between Diamond, Spade, Club or Heart private int rank; // Rank of a card, it goes between 1 till 13 (In order of A, 2, 3,..., 10, J, Q, K) /** * A constructor that requires a suit and rank input to initialize a card * @param suit * @param rank */ //CONSTRUCTORS public Card(String suit, int rank) { this.suit = suit; this.rank = rank; } /** * A constructor that uses a different Card to initialize the new card. * @param otherC */ public Card(Card otherC) { //Add code this.rank = otherC.getRank(); this.suit = otherC.getSuit(); } //OVERRIDED METHODS /** * Override of the method toSting this helps us control "how to print a card object." * @return The string "[R,S]" where R is rank and S is suit */ @Override public String toString() { return "[" + rank + "," + suit + "]"; } /** * Override of the equals method to control how card objects are to be compared. * @return comparison */ @Override public boolean equals(Object c2) { if (!(c2 instanceof Card)) { throw new RuntimeException("Illegal argument to Card.equals()"); } Card card2 = (Card) c2; return ((this.getSuit().equals(card2.getSuit())) && // this.suit same as this.getsuit() ?? (this.getRank() == card2.getRank())); } //GETTERS AND SETTERS /** * Suit Getter * @return suit */ public String getSuit() { return suit; } /** * Rank Getter * @return rank */ public int getRank() { return rank; } /** * Suit Setter * @return suit */ public void setSuit(String suit) { this.suit = suit; } /** * Rank Setter * @return rank */ public void setRank(int rank) { this.rank = rank; } //METHODS /** * Checks if two cards have the same suit * @param card2 * @return boolean */ public boolean sameSuitAs(Card card2) { return ( this.getSuit().equals(card2.getSuit())); //difference of this.suit.getSuit() to this.getSuit(); ? //this.suit.getSuit(); is undefined??? } /** * Checks if two cards have the same rank * @param card2 * @return boolean */ public boolean sameRankAs(Card card2) { return (this.getRank() == card2.getRank()); } /** * Returns if a card is an ace * @return boolean */ public boolean isAnA() { //Add code if (this.suit == "Spade" && this.rank==1) { return true; } else return false; //return this.suit == ("Spade"); // difference between == and equals ? } /** * Checks if two cards have the same rank * @param c * @return boolean */ public boolean isPair(Card c) { //Add code if (sameRankAs(c)){ return true; } else { return false; //Temporary Return } } /** * Checks if three cards have the same suit or rank // instructions were wrong. Its or instead of and * @param c1, c2 * @return boolean */ public boolean isTrio(Card c1, Card c2) { //Add code if(this.sameRankAs(c1) && this.sameRankAs(c2) || this.sameSuitAs(c1) && this.sameSuitAs(c2)) { return true; } else { return false; } } /** * Checks if four cards have the same suit and rank * @param c1, c2, c3 * @return boolean */ public boolean isFourTuple(Card c1, Card c2, Card c3) { //Add code if(this.equals(c1) && this.equals(c2)&&this.equals(c3)) { return true; } else { return false; //Temporary Return } } /** * A method that checks if the target card c1 is a rank * higher than the object card. * @return boolean */ public boolean isConsecutive(Card c1) { return rank + 1 == c1.getRank(); } /** * A method that returns true as soon a it has found * that the given card exist in the deck * @param target * @return boolean */ public boolean cardExistsIn(Card[] deck) { //Add code for(int i=0; i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!