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

*** In Java *** I need a PlayingCardTest Class to the following PlayingCard clas

ID: 3578813 • Letter: #

Question

*** In Java ***

I need a PlayingCardTest Class to the following PlayingCard class

PlayingCardTester – This class will be the one we execute(ie. contains the main method we execute). It will create instances of PlayingCard objects, calls methods on the PlayingCard class, and finally output each PlayingCard's content through calls to it's toString() method.

The PlayingCardTester must do the following at a minimum:

Creates 3 separate instances of PlayingCard objects

Calls the setSuit and setValue method for each of the 3 PlayingCards or uses an over loaded constructor for populating the suit and value attributes.

Outputs the variable values for each of the 3 PlayingCards (ie. Calls the toString() method for each PlayingCard).

Calls and outputs the results of calling a given PlayingCard's equals method passing it another PlayingCard.

public class PlayingCard{
String suit;
String value;
public PlayingCard(String suit, String value){
this.suit = suit;
this.value = value;
}

public PlayingCard(){
this.suit = null;
this.value = null;
}

public void setSuite(String suit){
this.suit = suit;
}

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

public String toString(){
return this.suit + "-->" + this.value;
}

public String getSuit(){
return this.suit;
}

public String getValue(){
return this.value;
}

public boolean equals(Object obj) {
boolean result = false;
if (obj instanceof PlayingCard) {
PlayingCard objCard = (PlayingCard)obj;
if (getSuit().equals(objCard.getSuit()) && getValue().equals(objCard.getValue())) {
result = true;
}
}
return result;
}
}

Explanation / Answer

PlayingCardTest.java

public class PlayingCardTest {

public static void main(String[] args)
{

PlayingCard p1=new PlayingCard("spade","jack");
System.out.println("Choosen Card is");

System.out.println(p1.toString());

PlayingCard p2=new PlayingCard("spade","Queen");
System.out.println("Choosen Card is");
System.out.println(p2.toString());
PlayingCard p3=new PlayingCard("spade","jack");
System.out.println("Choosen Card is");
System.out.println(p3.toString());
  
System.out.println("Output of equals Method");
  
boolean b=p1.equals(p2);
if(b==true)
{
System.out.println(p1.toString() +" is equal to "+ p2.toString());
}
else
System.out.println(p1.toString() +" is not equal to "+ p2.toString());
  
b=p2.equals(p3);
if(b==true)
{
System.out.println(p2.toString() +" is equal to "+ p3.toString());
}
else
System.out.println(p2.toString() +" is not equal to "+ p3.toString());
}
  
  
}