Question
Help Completing methods Also whats the difference between this.suit.getSuit() to this.getSuit(); ? Thank you. Java Code: public class Card { //INSTANCE VARIABLES private String suit;
Help Completing methods
Also whats the difference between this.suit.getSuit() to this.getSuit(); ?
Thank you.
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.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())); } /** * 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 return this.suit == ("Spade"); } /** * Checks if two cards have the same rank * @param c * @return boolean */ public boolean isPair(Card c) { //Add code return false; //Temporary Return } /** * Checks if three cards have the same suit and rank * @param c1, c2 * @return boolean */ public boolean isTrio(Card c1, Card c2) { //Add code return false; //Temporary Return } /** * 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 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 return false; //Temporary Return } /** * A method that returns true as soon as it has found an existing pair * in the deck * @return boolean */ public boolean pairExists(Card[] deck) { //Add code return false; //Temporary Return } /** * A method that returns a boolean as soon as it knows if a * deck is a flush. * Note: When we say flush, we mean that all the cards in * the deck are of the same suit. * @return boolean */ public boolean isFlush(Card[] deck) { //Add code return false; //Temporary Return } /** * A method that returns a boolean as soon as it knows if a * deck is a consecutive straight. * Note: When we say consecutive straight, we mean that all * the cards in the deck are in ascending order without * ordering the cards themselves. * @return boolean */ public boolean isConsecutiveStraight(Card[] deck) { //Add code return false; //Temporary Return } /** * A method that checks if the deck is a consecutive * straight flush with the previously mentioned restrains. * @return */ public boolean isConsecutiveStraightFlush(Card[] arr) { //Add code return false; //Temporary Return } }
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