Не проходит условие: в методе fight реализовать механизм драки котов в зависимости от их веса, возраста и силы.
Рекомендация от ментора: нужно сравнить каждый критерий по отдельности, и победителем будет тот, у которого больше "победивших" критериев.
Что я и делаю: n1 и n2 - счётчики "победивших" критериев. wtf?
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 n1 = 0, n2 = 0;
if (this.age > anotherCat.age)
n1++;
else
n2++;
if (this.weight > anotherCat.weight)
n1++;
else
n2++;
if (this.strength > anotherCat.strength)
n1++;
else
n2++;
return (n1 > n2);
}
public static void main(String[] args) {
Cat cat1 = new Cat();
cat1.age = 5;
cat1.strength = 5;
cat1.weight = 5;
Cat cat2 = new Cat();
cat2.age = 7;
cat2.strength = 4;
cat2.weight = 4;
boolean result_of_the_fight12 = false, result_of_the_fight21 = false;
result_of_the_fight12 = cat1.fight(cat2);
result_of_the_fight21 = cat2.fight(cat1);
if (result_of_the_fight12)
System.out.println(1);
else
System.out.println(0);
if (result_of_the_fight21)
System.out.println(1);
else
System.out.println(0);
}
}