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

public class Card { private char suit ; // The suit of the card (C,D,H,S) privat

ID: 3539020 • Letter: P

Question

 public class Card {     private char suit;    // The suit of the card (C,D,H,S)     private char value;    // The value of the card (A,2,3...10,J,Q,K)     private String SuitName; // The suit's name(eg, "Heart")     private String ValueName; // The Value's name (eg, "ace")       /**      * Constructor for objects of class Card      * Creates a Card object with the parameter values as attribute values      */         Card(char suit, char value)     {          this.suit = suit;          this.value = value;     }      /**      * Grabs the required char attribute from value.      *       * @return     Value of the Card      */       public char getValue()     {        return value;     }       /**      * Grabs the required char attribute from suit.      *      * @return     Suit of the Card      */       public char getSuit()     {         return suit;     }      /**      * Sets/changes the value of the Card.      *       * @param  char value   Asks for the attribute in value as a character      */       public void setValue(char value)     {         this.value = value;     }      /**      *Sets/changes the suit of the Card.      *       * @param  char suit  Asks for the attribute in suit as a character      */       public void setSuit(char suit)     {         this.suit = suit;     }       /**      *This method returns the suit of the Card as a String.      * (eg "Diamond")      * @return     The suit of the Card as a String.       */       public String getSuitName()     {          if(suit == 'C')          {              this.SuitName = "Clubs";             }              else if(suit == 'D')          {              this.SuitName = "Diamonds";             }          else if(suit == 'H')          {              this.SuitName = "Hearts";             }          else if(suit == 'S')          {              this.SuitName = "Spades";             }           return SuitName;     }    ]  /**      * This method returns the value of the Card as a Sting      * (eg "King" or "6")      * @return     The value of the Card as a String.      */     public String getValueName()     {         if(value == 'A')          {              this.ValueName = "Ace";             }              else if(value == 'J')          {              this.ValueName = "Jack";             }              else if(value == 'Q')          {              this.ValueName = "Queen";             }              else if(value == 'K')          {              this.ValueName = "King";             }         return ValueName;     }       /**      * Returns - 1 if anotherCard's suit is before, 0 if equal to and +1 if after.      * The order is 'C','D','H','S'.      *       * @param  char anotherCardsSuit         * @return           */     public int compareSuit(char anotherCardsSuit)     {       }    public int compareValue(char anotherCardsValue)     {         return value;     }      /**      *       * @param  Card anotherCard       * @return     True if the Cards have the same suit and value;       * false otherwise      */     public boolean equals(Card anotherCard)     {       return true;     }

Explanation / Answer

please rate - thanks

ask if any questions



import java.util.*;
public class CardTester
{public static void main(String [] args)
{Card a=new Card('H','3');
Card b=new Card('D','5');
Card c=new Card('D','5');

System.out.println(b.equals(c));
System.out.println(a.equals(b));
System.out.println(b.compareValue(c));
System.out.println(a.compareValue(b));
System.out.println(b.compareSuit(c));
System.out.println(a.compareSuit(b));

c.setValue('A');
System.out.println(b.equals(c));
System.out.println(a.equals(b));
System.out.println(b.compareValue(c));
System.out.println(a.compareValue(b));
System.out.println(b.compareSuit(c));
System.out.println(a.compareSuit(b));
}
}

-------------------------------------


public class Card
{
    private char suit;    // The suit of the card (C,D,H,S)
    private char value;    // The value of the card (A,2,3...10,J,Q,K)
    private String SuitName; // The suit's name(eg, "Heart")
    private String ValueName; // The Value's name (eg, "ace")

    /**
     * Constructor for objects of class Card
     * Creates a Card object with the parameter values as attribute values
     */

      Card(char suit, char value)
    {
         this.suit = suit;
         this.value = value;
    }

   /**
     * Grabs the required char attribute from value.
     *
     * @return     Value of the Card
     */

    public char getValue()
    {
       return value;
    }

    /**
     * Grabs the required char attribute from suit.
     *
     * @return     Suit of the Card
     */

    public char getSuit()
    {
        return suit;
    }

   /**
     * Sets/changes the value of the Card.
     *
     * @param char value   Asks for the attribute in value as a character
     */

    public void setValue(char value)
    {
        this.value = value;
    }

   /**
     *Sets/changes the suit of the Card.
     *
     * @param char suit Asks for the attribute in suit as a character
     */

    public void setSuit(char suit)
    {
        this.suit = suit;
    }

    /**
     *This method returns the suit of the Card as a String.
     * (eg "Diamond")
     * @return     The suit of the Card as a String.
     */

    public String getSuitName()
    {
         if(suit == 'C')
         {
             this.SuitName = "Clubs";
            }
             else if(suit == 'D')
         {
             this.SuitName = "Diamonds";
            }
         else if(suit == 'H')
         {
             this.SuitName = "Hearts";
            }
         else if(suit == 'S')
         {
             this.SuitName = "Spades";
            }

        return SuitName;
    }


     /* This method returns the value of the Card as a Sting
     * (eg "King" or "6")
     * @return     The value of the Card as a String.
     */
    public String getValueName()
    {
        if(value == 'A')
         {
             this.ValueName = "Ace";
            }
             else if(value == 'J')
         {
             this.ValueName = "Jack";
            }
             else if(value == 'Q')
         {
             this.ValueName = "Queen";
            }
             else if(value == 'K')
         {
             this.ValueName = "King";
            }
        return ValueName;
    }

    /**
     * Returns - 1 if anotherCard's suit is before, 0 if equal to and +1 if after.
     * The order is 'C','D','H','S'.
     *
     * @param char anotherCardsSuit  
     * @return    
     */
    public int compareSuit(Card anotherCardsSuit)
    {if(this.suit==anotherCardsSuit.suit)
            return 0;
    else if(anotherCardsSuit.suit<this.suit)
           return -1;
    else
            return 1;

    }

public int compareValue(Card anotherCardsValue)
    {int n1,n2;
    n1=numericValue(this.value);
    n2=numericValue(anotherCardsValue.value);
        if(n1==n2)
            return 0;
    else if(n1<n2)
           return -1;
    else
            return 1;
    }

   /**
     *
     * @param Card anotherCard
     * @return     True if the Cards have the same suit and value;
     * false otherwise
     */
    public boolean equals(Card anotherCard)
    {int n1,n2;
    n1=numericValue(this.value);
    n2=numericValue(anotherCard.value);
    if(n1==n2&&this.suit==anotherCard.suit)
        return true;
    else
         return false;
    }
public static int numericValue(char c)
{switch(c)
   {case 'A': return 1;
    case 'J': return 11;
    case 'Q': return 12;
    case 'K': return 13;
    default:   return (int)(c-'0');
    }
}
}