For this assignment you will need to write and submit two ja
For this assignment you will need to write and submit two java programs:
PlayingCard – The UML diagram for this class is displayed below. The PlayingCard class will be a java program for representing an individual playing card from a deck of cards. For example, the jack of spades represents one instance of a PlayingCard with suit = Spades and value = Jack.
!!! NOTE: you do not need to write the equals method as shown in the UML diagram below.
PlayingCardTester – Much like the Student and Student_Tester classes looked at in class today. 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.
!!! NOTE: none of your methods will be static, why? So we can create instances of PlayingCard s!!!
The equals method:
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;
}
Solution
PlayingCard.java
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;
     }
 }
PlayingCardTester.java
public class PlayingCardTester{
     public static void main(String[] args) {
         PlayingCard card1 = new PlayingCard(\"Spades\", \"Jack\");
         PlayingCard card2 = new PlayingCard(\"Hearts\", \"Ace\");
         PlayingCard card3 = new PlayingCard(\"Hearts\", \"Ace\");
         card1.toString();
         card2.toString();
         card3.toString();
         if (card1.equals(card2)){
             System.out.println(\"Card 1 and Card 2 are equal\");
         }
        if (card2.equals(card3)){
             System.out.println(\"Card 2 and Card 3 are equal\");
         }
        if (card3.equals(card1)){
             System.out.println(\"Card 3 and Card 1 are equal\");
         }
     }
 }


