Question: In this assignment you will create a class that represents a playing card. All cards have suit and rank. Your class will extend this interface

In this assignment you will create a class that represents a playing card. All cards have suit and rank. Your class will extend this interface CardInterface.javaIn this assignment you will create a class that represents a playing You will complete all of the methods that are described in CardInterface.java

You will name your class Card.java. You will include two constructors - a no argument constructor that sets the rank to two and the suit to Spades. Add a second constructor that has parameters for suit and rank. If suit is out of range, set it to spades, and if rank is out of range, set it to two.

Test your Card class in a separate file named CardTester.java CardTester will contain a main method that instantiates several cards and tests ALL methods in Card.java. Be sure to use the CardInterface constants, and implement each method in the CardInterface in your Card class.

Recall that you can add private helper methods to the Card class, and additional methods if your wish. You are not restricted to using only the methods declared in the CardInterface.

Paste the output from the tester in a comment at the end of the tester, then zip your Card.java file, your CardTester.java file and the provided CardInterface.java file.

/** * @author wernerla An interface for a playing card * */ public interface CardInterface { // Define the suit public static final int SPADES = 1; public static final int HEARTS = 2; public static final int CLUBS = 3; public static final int DIAMONDS = 4; // define the card rank public static final int TWO = 2; public static final int THREE = 3; public static final int FOUR = 4; public static final int FIVE = 5; public static final int SIX = 6; public static final int SEVEN = 7; public static final int EIGHT = 8; public static final int NINE = 9; public static final int TEN = 10; public static final int JACK = 11; public static final int QUEEN = 12; public static final int KING = 13; public static final int ACE = 14;

/** * Returns the face value of the card, where the cards' values are specified * in a set of constants. * * @return integer value of the rank. */ public int getRank(); // /** * Returns the suit value of the card, where the suits' values are specified * in a set of constants. * * @return integer value of the suit - 1, 2, 3, 4. */ public int getSuit(); // /** * Sets the rank of the card, a number from 2 to 14, * representing the face value of a numeric card, or 11 * for Jack, 12 for Queen, 13 for King and 14 for Ace * * @param rank * the rank to set * if rank is not valid, rank is set to 2. */ public void setRank(int rank); // /** * sets the suit of the card, a number from 1 to 4, * representing spades, hearts, clubs, diamonds respectively. * @param suit * the suit to set * if suit is not valid, suit is set to spades (1) */ public void setSuit (int suit); // /** * Compares suit of two cards * * @param other * - Card to compare to * @return true if other.suit == this.suit */ public boolean sameSuit(Card other); // /** * Compares the rank of 2 cards; * * @param other * - other Card * @return difference in rank as this.rank-other.rank; returns * Integer.MAX_VALUE if other is null. */ public int compareTo(Card other); // /** * Returns a String representation of the card's face value. "Two", "Three", * ... "Ten", "Jack", "Queen", "King", "Ace". * * @return String representation of face value. */ public String getRankAsString();

// /** * Returns a String representation of the card's suit vaue."Spades", * "Hearts","Diamonds","Clubs" * @return String representation of Suit value. */ public String getSuitAsString(); @Override /** * Returns a string indicating suit and rank as raw integers * @return string representation of numeric suit and rank */ public String toString(); }

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!