I don't understand this, I have 3 fights in my code, but still, there is an error saying "You need to conduct three fights." Any idea why this happens?
package com.codegym.task.task05.task0505;
/*
Feline carnage
*/
public class Solution {
public static void main(String[] args) {
Cat tom = new Cat("Tom", 4, 12, 580);
Cat ben = new Cat("Ben", 9, 5, 650);
Cat nicky = new Cat("Nicky", 2, 6, 433);
tom.fight(nicky);
tom.fight(ben);
ben.fight(nicky);
System.out.println(tom.fight(nicky));
System.out.println(tom.fight(ben));
System.out.println(ben.fight(nicky));
}
public static class Cat {
protected String name;
protected int age;
protected int weight;
protected int strength;
public Cat(String name, int age, int weight, int strength) {
this.name = name;
this.age = age;
this.weight = weight;
this.strength = strength;
}
public boolean fight(Cat anotherCat) {
int ageAdvantage = this.age > anotherCat.age ? 1 : 0;
int weightAdvantage = this.weight > anotherCat.weight ? 1 : 0;
int strengthAdvantage = this.strength > anotherCat.strength ? 1 : 0;
int score = ageAdvantage + weightAdvantage + strengthAdvantage;
return score > 2; // return score > 2 ? true : false;
}
}
}