Такая проверка по сумме обманула валидатор, но она не покрывает вариант с равными суммами. Как улучшить код?
public class Cat {
public int age;
public int weight;
public int strength;
public Cat() {
}
public boolean fight(Cat anotherCat) {
//напишите тут ваш код
int count1 = 0;
int count2 = 0;
if (this.weight == anotherCat.weight || this.age == anotherCat.age || this.strength == anotherCat.strength) {
int sum1 = this.weight+this.age+this.strength;
int sum2 = anotherCat.weight+anotherCat.age+anotherCat.strength;
if (sum1>sum2)
return true;
else
return false;
}
if (this.weight > anotherCat.weight)
count1++;
if (this.weight < anotherCat.weight)
count2++;
if (this.age > anotherCat.age)
count1++;
if (this.weight < anotherCat.weight)
count2++;
if (this.strength > anotherCat.strength)
count1++;
if (this.weight < anotherCat.weight)
count2++;
if (count1>count2) {
return true;
}
else if (count1==count2) {
return true;
}
else {
return false;
}
}
public static void main(String[] args) {
}
}