Доброй ночи,
Прошу подсказать в чем же заключается ошибка при данном методе решения.
Пробовал несколькими способами, так же созданием отдельного класса, который считает и передает параметры через глобальную переменную в класс fight.
Так же пробовал
if((this.strength > strength) && (this.weight > this.weight) && (this.age > age)) return true;
if((this.strength > strength) && (this.weight < weight) && (this.age < age)) return false;
if((this.strength > strength) && (this.weight > weight) && (this.age < age)) return true;
if((this.strength > strength) && (this.weight < weight) && (this.age > age)) return true;
if((this.strength < strength) && (this.weight > weight) && (this.age > age)) return true;
if((this.strength < strength) && (this.weight < weight) && (this.age > age)) return true;
if((this.strength < strength) && (this.weight > weight) && (this.age < age)) return true;
if((this.strength < strength) && (this.weight < weight) && (this.age < age)) return true;
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 countAboveParams = 0;
if (this.age > age) {
countAboveParams++;
}
if (this.age < age) countAboveParams--;
if (this.weight > weight) countAboveParams++;
else if (this.weight < weight) countAboveParams--;
if (this.strength > strength) countAboveParams++;
else if (this.strength < strength) countAboveParams--;
if (countAboveParams > 0) return true;
if (countAboveParams < 0) return false;
return false;
}
public static void main(String[] args) {
Cat cat1 = new Cat();
cat1.age = 15;
cat1.weight = 2800;
cat1.strength = 100;
Cat cat2 = new Cat();
cat2.age = 12;
cat2.weight = 1400;
cat2.strength = 2800;
System.out.println(cat1.fight(cat2));
}
}