package com.javarush.task.task05.task0502;
/*
Реализовать метод fight
*/
public class Cat {
public int age;
public int weight;
public int strength;
public Cat(int age, int weight, int strength) {
}
public boolean fight(Cat anotherCat) {
int countThis = 0, countAnother = 0;
if (this.age > anotherCat.age) {
countThis = countThis + 1;
}
if (anotherCat.age == this.age) {
countAnother = countAnother + 1;
countThis = countThis + 1;
}
if (this.age < anotherCat.age) {
countAnother = countAnother + 1;
}
if (this.weight > anotherCat.weight ) {
countThis = countThis + 1;
}
if (anotherCat.weight == this.weight) {
countAnother = countAnother + 1;
countThis = countThis + 1;
}
if (this.weight < anotherCat.weight ) {
countAnother = countAnother + 1;
}
if (this.strength > anotherCat.strength) {
countThis = countThis + 1;
}
if (anotherCat.strength == this.strength) {
countAnother = countAnother + 1;
countThis = countThis + 1;
}
if (this.strength < anotherCat.strength) {
countAnother=countAnother+1;
}
return (countThis > countAnother);
}
public static void main(String[] args) {
Cat cat1=new Cat(10,8,67);
Cat cat2=new Cat(9,6,66);
System.out.println(cat1.fight(cat2));
System.out.println(cat2.fight(cat1));
}
}Pavel
35 уровень
Что я делаю не так? не могу понять почему всегда false ?
Решен
Комментарии (1)
- популярные
- новые
- старые
Для того, чтобы оставить комментарий Вы должны авторизоваться
hidden #598481
11 сентября 2020, 15:50полезный
Ты поля объектов не заполняешь в конструкторе.
А еще условие требует, чтобы у тебя был конструктор по умолчанию.
+1