Not sure what is wrong with this modified code - this checks for equal conditions as well!
package com.codegym.task.task05.task0502;
/*
Implement the fight method
*/
public class Cat {
public int age;
public int weight;
public int strength;
String name;
public Cat() {
}
public boolean fight(Cat anotherCat) {
boolean won = false;
if ((this.strength > anotherCat.strength) || (this.weight > anotherCat.weight) || (this.age < anotherCat.age))
won = true;
else if ((this.strength == anotherCat.strength) && (this.weight == anotherCat.weight) && (this.age == anotherCat.age) && (this.name == "Favorite cat"))
won = true;
return won;
}
public static void main(String[] args) {
Cat cat1 = new Cat();
Cat cat2 = new Cat();
cat1.age = 4;
cat1.weight = 24;
cat1.strength = 98;
cat1.name = "Favorite cat";
cat2.age = 4;
cat2.weight = 24;
cat2.strength = 99;
cat2.name = "Unknown cat";
System.out.println(cat1.fight(cat2));
System.out.println(cat2.fight(cat1));
}
}