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 cat = 0, another = 0;
if (this.weight > anotherCat.weight) cat++;
else another++;
if (this.age > anotherCat.age) cat++;
else another++;
if (this.strength > anotherCat.strength) cat++;
else another++;
if (cat < another) return false;
return true;
}
public static void main(String[] args) {
Cat cat = new Cat();
cat.age = 3;
cat.strength = 10;
cat.weight = 5;
Cat cat2 = new Cat();
cat.age = 1;
cat.strength = 3;
cat.weight = 2;
System.out.println(cat2.fight(cat));
}
}
Илья
6 уровень
Ошибка на этом пункте "В методе fight реализовать механизм драки котов в зависимости от их веса, возраста и силы согласно условию." но программа работает правильно.
Решен
Комментарии (2)
- популярные
- новые
- старые
Для того, чтобы оставить комментарий Вы должны авторизоваться
Евгений Senior Java Developer
3 марта 2020, 09:12решение
видимо валидатору не нравится, что если у тебя сила ЭТОГО кота больше силы другого кота, то ты увеличиваешь cat++, иначе (если меньше или равно!!), тогда увеличиваешь another++. НО это нелогично. если сила равна - не надо увеличивать ничей "итог".
+2
Евгений Senior Java Developer
3 марта 2020, 09:14
public boolean fight(Cat anotherCat) {
int cat = 0, another = 0;
if (this.weight > anotherCat.weight) cat++;
else if (this.weight < anotherCat.weight) another++;
if (this.age > anotherCat.age) cat++;
else if (this.age < anotherCat.age) another++;
if (this.strength > anotherCat.strength) cat++;
else if (this.strength < anotherCat.strength) another++;
if (cat < another) return false;
return true;
}
0