Решение подсмотрел, но все разобрал и понял, как все работает.
Результат выдает нужный, но проверку не проходит.
package com.javarush.task.task05.task0502;
/*
Реализовать метод fight
*/
public class Cat {
public int age;
public int weight;
public int strength;
public Cat() {
}
public boolean fight(Cat anotherCat) {
int aAge = this.age > anotherCat.age ? 1 : 0;
int aWeight = this.weight > anotherCat.weight ? 1 : 0;
int aStrenght = this.strength > anotherCat.strength ? 1 : 0;
int sum = aAge + aWeight + aStrenght;
return sum > 2;
}
public static void main(String[] args) {
Cat cat1 = new Cat();
cat1.age = 2;
cat1.weight = 2;
cat1.strength = 2;
Cat cat2 = new Cat();
cat2.age = 2;
cat2.weight = 2;
cat2.strength = 2;
System.out.println(cat1.fight(cat2));
}
}