This question already has an answer here:
- Compare two return values [duplicate] 1 answer
How do I compare two return values of an object? Because when I'm doing this in my code and the return values is different each time. Here is my code:
public static void Card_Initialization(){
Red_Dog c1 = new Red_Dog();
Red_Dog c2 = new Red_Dog();
Cards_Match(c1);
System.out.println(card_num+card_suit);
Cards_Match(c2);
System.out.println(card_num+card_suit);
System.out.println(Cards_Match(c1) == Cards_Match(c2));//to check really if it is equal
}
public static int Cards_Match(Red_Dog rd){
card = (int)(Math.random() * deck.length);
if(card >= 0 && card <=3)
{
card_num = cards[0];
}
else if(card >= 4 && card <=7)
{
card_num = cards[1];
}
else if(card >= 8 && card <=11)
{
card_num = cards[2];
}
else if(card >= 12 && card <=15)
{
card_num = cards[3];
}
else if(card >= 16 && card <=19)
{
card_num = cards[4];
}
else if(card >= 20 && card <=23)
{
card_num = cards[5];
}
else if(card >= 24 && card <=27)
{
card_num = cards[6];
}
else if(card >= 28 && card <=31)
{
card_num = cards[7];
}
else if(card >= 32 && card <=35)
{
card_num = cards[8];
}
else if(card >= 36 && card <=39)
{
card_num = cards[9];
}
else if(card >= 40 && card <=43)
{
card_num = cards[10];
}
else if(card >= 44 && card <=47)
{
card_num = cards[11];
}
else if(card >= 48 && card <=51)
{
card_num = cards[12];
}
if(card % 4 == 0)
{
card_suit = suits[0];
}
else if(card % 4 == 1)
{
card_suit = suits[1];
}
else if(card % 4 == 2)
{
card_suit = suits[2];
}
else if(card % 4 == 3)
{
card_suit = suits[3];
}
return card;
}
Result: 1st run: AceSpades AceSpades false
2nd run: AceSpades AceSpades true