Ничего не понятно в методе:
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;
}
А тем более здесь:
int ageAdvantage = this.age > anotherCat.age ? 1 : 0;
Что ваапще значит это:
anotherCat.age ? 1 : 0;
Помогите пожалуйста!
package com.javarush.task.task05.task0505;
/*
Кошачья бойня
*/
public class Solution {
public static void main(String[] args) {
Cat Vashya = new Cat("Ваш'я",12,44,100);
Cat Kotopas = new Cat("Котопас",42,110,9999);
Cat casha = new Cat("Каша",1,1,99999999);
}
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;
}
}
}