Пробую сравнить двух котов через compareTo. Код не проходит компиляцию.
package com.javarush.task.task05.task0502;
/*
Реализовать метод fight
*/
public class Cat implements Comparable <Cat> {
public int age;
public int weight;
public int strength;
public Cat() {
}
@Override
public int compareTo(Cat anotherCat) {
public boolean fight(Cat anotherCat) {
//напишите тут ваш код
int c1, c2;
c1 = cat1.age + cat1.weight + cat1.strengtg;
c2 = anotherCat.age + anotherCat.weight + anotherCat.strength;
int result = c1.compareTo(c2);
if (result == 0) {return true; System.out.println('Ничья');}
if (result > 0) {return true; System.output.println('Кот1 победил');}
if (result < 0) {return false; System.out.println('Кот2 победил');}
if (result == 0) {return true; System.out.println('Ничья');}
return result;
}
}
public static void main(String[] args) {
Cat cat1 = new Cat();
cat1.age = 2;
cat1.weight = 4;
cat1.strengh = 6;
Cat cat2 = new Cat();
cat2.age = 1;
cat2.weight = 6;
cat2.strengh = 7;
cat1.fight(cat2);
cat2 fight(cat1);
}
}