Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Elevens Activity 1 - Card Class Implementation Complete the implementation of th

ID: 3672340 • Letter: E

Question

Elevens Activity 1 - Card Class Implementation

Complete the implementation of the provided Card class with a

-a constructor that takes two String parameters that represent the card’s rank and suit, and an int parameter that represents the point value of the card;

-accessor methods for the card’s rank, suit, and point value;

-a method to test equality between two card objects; and

-the toString method to create a String that contains the rank, suit, and point value of the card object. The string should be in the following format:

rank of suit (point value = pointValue)

2. Once you have completed the Card class, find the CardTester.java file in the Activity 1 folder. Create three Card objects and test each method for each Card object.

/**
* Card.java
*
* <code>Card</code> represents a playing card.
*/
public class Card {

   /**
   * String value that holds the suit of the card
   */
   private String suit;

   /**
   * String value that holds the rank of the card
   */
   private String rank;

   /**
   * int value that holds the point value.
   */
   private int pointValue;


/**
   * Creates a new <code>Card</code> instance.
   *
   * @param cardRank a <code>String</code> value
   * containing the rank of the card
   * @param cardSuit a <code>String</code> value
   * containing the suit of the card
   * @param cardPointValue an <code>int</code> value
   * containing the point value of the card
   */
   public Card(String cardRank, String cardSuit, int cardPointValue) {
       /* *** TO BE IMPLEMENTED IN ACTIVITY 1 *** */
   }


   /**
   * Accesses this <code>Card's</code> suit.
   * @return this <code>Card's</code> suit.
   */
   public String suit() {
       /* *** TO BE IMPLEMENTED IN ACTIVITY 1 *** */
}

   /**
   * Accesses this <code>Card's</code> rank.
   * @return this <code>Card's</code> rank.
   */
   public String rank() {
       /* *** TO BE IMPLEMENTED IN ACTIVITY 1 *** */
   }

/**
   * Accesses this <code>Card's</code> point value.
   * @return this <code>Card's</code> point value.
   */
   public int pointValue() {
       /* *** TO BE IMPLEMENTED IN ACTIVITY 1 *** */
   }

   /** Compare this card with the argument.
   * @param otherCard the other card to compare to this
   * @return true if the rank, suit, and point value of this card
   * are equal to those of the argument;
   * false otherwise.
   */
   public boolean matches(Card otherCard) {
       /* *** TO BE IMPLEMENTED IN ACTIVITY 1 *** */
   }

   /**
   * Converts the rank, suit, and point value into a string in the format
   * "[Rank] of [Suit] (point value = [PointValue])".
   * This provides a useful way of printing the contents
   * of a <code>Deck</code> in an easily readable format or performing
   * other similar functions.
   *
   * @return a <code>String</code> containing the rank, suit,
   * and point value of the card.
   */
   @Override
   public String toString() {
       /* *** TO BE IMPLEMENTED IN ACTIVITY 1 *** */
   }
}

/**
* This is a class that tests the Card class.
*/
public class CardTester {

   /**
   * The main method in this class checks the Card operations for consistency.
   *   @param args is not used.
   */
   public static void main(String[] args) {
       /* *** TO BE IMPLEMENTED IN ACTIVITY 1 *** */
   }
}

Explanation / Answer

Card.java


public class Card {

   private String suit;
   private String rank;
   private int pointValue;


   public Card(String cardRank, String cardSuit, int cardPointValue) {
       rank = cardRank;
                suit = cardSuit;
                pointValue = cardPointValue;
   }
      
   public String suit() {
       return suit;
         }

   public String rank() {
       return rank;
   }

   public int pointValue() {
       return pointValue;
   }

   public boolean matches(Card otherCard) {
       if(suit == otherCard.suit() && rank == otherCard.rank() && pointValue == otherCard.pointValue())
                    return true;
                else
                    return false;                  
                 
   }

   public String toString() {
       return rank + " of " + suit + "(point value = " + pointValue + ")";
   }
}


CardTester.java

public class CardTester {

   public static void main(String[] args) {
       Card c1, c2, c3;
                c1 = new Card("Queen", "Spades", 10);
                c2 = new Card("Ace", "Hearts", 1);
                c3 = new Card("Queen", "Spades", 10);
                System.out.println(c1);
                System.out.println(c2);
                System.out.println(c3);
              
                if(c1.matches(c3))
                    System.out.println("c1 and c3 match");
                else
                    System.out.println("c1 and c3 match");
              
                if(c1.matches(c2))
                    System.out.println("c1 and c2 match");
                else
                    System.out.println("c1 and c2 match");
              
              
   }
}


output


Queen of Spades(point value = 10)                                                                                                                           
Ace of Hearts(point value = 1)                                                                                                                              
Queen of Spades(point value = 10)                                                                                                                           
c1 and c3 match                                                                                                                                             
c1 and c2 match                                                                                                                                             

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote