I have to write an equals method which will return true if 2 intances of the PlayingCard class have the same value for suit and rank. I also have to write a hashCode method, that will return a hash code for the instance of the class. Thanks! Hope that makes sense. public class PlayingCard{ private String suit, rank; private int value; PlayingCard(String s, String r, int v){ suit = s; rank = r; value = v; } public String suit(){return suit;} public String rank(){return rank;} public int value(){return value;} public String toString(){return suit+" "+rank+" "+value;} }
Need a hand with this for Java, don't understand what exactly is being asked.
Here given is a class representing a playing card with the attributes rank, value and suit.
I have to write an equals method which will return true if 2 intances of the PlayingCard class have the same value for suit and rank.
I also have to write a hashCode method, that will return a hash code for the instance of the class. Thanks! Hope that makes sense.
public class PlayingCard{
private String suit, rank;
private int value;
PlayingCard(String s, String r, int v){
suit = s; rank = r; value = v;
}
public String suit(){return suit;}
public String rank(){return rank;}
public int value(){return value;}
public String toString(){return suit+" "+rank+" "+value;}
}
Step by step
Solved in 3 steps