Добрый день, программисты!
Компилятор выдает ошибку:
Возможно переменная "result" не проинициализирована.
файл com/javarush/task/task05/task0502/Cat.java, строка 48, позиция 1088
Не могу разобраться, почему программа ругается на переменную result, объявленную в методе.
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) {
boolean ageWin;
boolean wghtWin;
boolean strWin;
if (this.age <= anotherCat.age) ageWin = true;
else ageWin = false;
if (this.weight >= anotherCat.age) wghtWin = true;
else wghtWin = false;
if (this.strength >= anotherCat.strength) strWin = true;
else strWin = false;
boolean result;
if (ageWin == true)
{
if (wghtWin == true) result = true;
else if (strWin == true) result = true;
else result = false;
}
else if (ageWin == false)
{
if (wghtWin == true)
{
if (strWin == true) result = true;
else result = false;
}
else result = false;
}
return result;
//напишите тут ваш код
}
public static void main(String[] args) {
Cat cat1 = new Cat();
cat1.age = 1;
cat1.weight = 9;
cat1.strength = 9;
Cat cat2 = new Cat();
cat2.age = 2;
cat2.weight = 1;
cat2.strength = 1;
System.out.println(cat1.fight(cat2));
}
}