Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need assistance with the setter method and a check over for the rest.. I need assistance with the SuitsAndRanks array portion package skeleton; /** *

Need assistance with the setter method and a check over for the rest.. I need assistance with the SuitsAndRanks array portion

package skeleton;

/** * PlayingCard.java */

/** * This class as given represents a playing card with Suits but no Rank. Your * job is to implement Ranks by creating the code described at the TODO markers. * * @author Mitch Parry * @version May 6, 2013 */ public class PlayingCard { // Fields // TODO: Declare a SuitsAndRanks.Suit variable named suit; SuitsAndRanks.Suit suit;

// TODO: Declare a SuitsAndRanks.Rank variable named rank; SuitsAndRanks.Rank rank; /** * Constructor - each card assigned a rank and suit when created by the Deck * class. * */ // TODO: Create constructor with first parameter 'rank' and second // parameter 'suit' public PlayingCard(SuitsAndRanks.Rank rank, SuitsAndRanks.Suit suit) { // TODO: Assign suit passed via constructor to field suit this.suit = suit;

// TODO: Assign rank passed via constructor to field rank this.rank = rank; }

/** * Getter method that returns this card's Suit. * * @return Suit of this card */ // TODO: Write a getter method that returns this card's Suit public SuitsAndRanks.Suit getSuit() { return suit; }

/** * Getter method that returns this card's Rank. * * @return Rank of this card */ // TODO: Write a getter method that returns this card's Rank public SuitsAndRanks.Rank getRank() { return rank; }

/** * Sets the suit of the card. * * @param suit * The new suit for this card */ // TODO: Write a setter method for this card's Suit. public void setSuit(SuitsAndRanks.Suit suit) { }

/** * Sets the rank of this card. * * @param rank * The new rank for this card */ // TODO: Write a setter method for this card's Rank.

/* * TODO: Override the toString method to return a string in the following * format: "Rank Suit". */ /** * Returns a String representation of a PlayingCard. * * @return The string. */ @Override public String toString() { return ""; } }

public class SuitsAndRanks { /** * Provides the enumerated suits for playing cards in order of * * increasing importance for the game of bridge. */ //TODO: Create enum for Suit (i.e., CLUBS, DIAMONDS, HEARTS, SPADES) public enum Suit { CLUBS, DIAMONDS, HEARTS, SPADES };

/** * Provides the enumerated ranks for playing cards in ascending * order. */ // TODO: Create enum for Rank (ie TWO, THREE, ..., ACE) public enum Rank { TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE };

// TODO: Create a public static array of Suits named 'suits' // containing all the suits. public static Suit[] suits = Suit.values(); //TODO: Create a public static constant for the number of Suits. public static final int NUMSUITS = 4; // TODO: Create a public static array of Ranks named // 'ranks' containing all ranks. public static Rank[] ranks = Rank.values();

//TODO: Create a public static constant for the number of Ranks. public static final int NUMRANKS = 13;

/** * fetchSuit returns the Suit at a given index. * If the index is greater than the number of suits, * wrap the index back to zero using the mod operator. * * @param index Index into the 'suits' array * @return The Suit at that index */ //TODO: Create a public static method named 'fetchSuit' public static Suit fetchSuit(int index) { return suits[index % NUMSUITS]; } /** * fetchRank returns the Rank at a given index. * If the index is greater than the number of suits, * wrap the index back to zero using the mod operator. * * @param index Index into the 'ranks' array * @return The Rank at that index */ //TODO: Create a public static method named 'featchRank' public static Rank fetchRank(int index) { return ranks[index % NUMRANKS]; }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

More Books

Students also viewed these Databases questions