4 раза проверил - все так - что не так???
package com.javarush.task.task05.task0502;
/*
Реализовать метод fight
Нужно сравнить каждый критерий по отдельности, и победителем будет тот, у которого больше "победивших" критериев.
Метод должен определять, выиграли ли мы (this) бой или нет, т.е. возвращать true, если выиграли и false - если нет.
Если ничья и никто не выиграл, возвращаем либо true либо false, но должно выполняться условие:
если cat1.fight(cat2) возвращает true,
то cat2.fight(cat1) должен возвращать false.
*/
public class Cat {
public int age;
public int weight;
public int strength;
public Cat() {
}
public boolean fight(Cat anotherCat) {
int c1 = 0, c2 = 0;
// System.out.println(anotherCat.age + " " + this.age);
if (anotherCat.age > this.age){c2++;} else if (anotherCat.age == this.age) {c1 ++; c2++;}
else{c1++;}
if (anotherCat.weight > this.weight){c2++;} else if (anotherCat.weight == this.weight) {c1 ++; c2++;}
else {c1++;}
if (anotherCat.strength > this.strength){c2++;} else if (anotherCat.strength == this.strength) {c1 ++; c2++;}
else {c1++;}
// System.out.println(c2 + " " + c1);
return c2 >= c1;
}
public static void main(String[] args) {
// Cat cat1 = new Cat();
// cat1.strength =2;
// cat1.age = 3;
// cat1.weight = 4;
//
// Cat cat2 = new Cat();
// cat2.strength = 1;
// cat2.age = 2;
// cat2.weight = 3;
//
// System.out.println(cat1.fight(cat2));
// System.out.println(cat2.fight(cat1));
// System.out.println(cat1.fight(cat1));
//System.out.println(cat2.fight(cat1));
}
}