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 x = 0;
if (this.age != anotherCat.age) {
if (this.age > anotherCat.age) {
x++;
} else x--;
}
if (this.weight !=anotherCat.weight) {
if (this.weight >anotherCat.weight) {
x++;
} else x--;
if (this.strength !=anotherCat.strength) {
if (this.strength > anotherCat.strength) {
x++;
} else x--;
}
}
if (x > 0) {
return true;
} else return false;
}
public static void main(String[] args) {
}
}
Egor Subbotyn
22 уровень
намекните, чё не так?
Архивный
Комментарии (3)
- популярные
- новые
- старые
Для того, чтобы оставить комментарий Вы должны авторизоваться
Alex T
16 мая 2019, 21:18
а если возвраст и вес равны, а силы нет?
0
Egor Subbotyn
17 мая 2019, 06:28
ну следовательно не войдём в 1 и во 2 Ifы, x будет или +1(true) или -1(false)
0
Egor Subbotyn
17 мая 2019, 06:31
спасибо, как говориться утро вечера мудренее=)) скобка не там стоит (не закрывает 2й if)
0