Пробывал разные методы подхода и не как не выполняется 4-ый пункт.
package com.javarush.task.task05.task0502;
/*
Реализовать метод fight
Реализовать метод boolean fight(Cat anotherCat):
реализовать механизм драки котов в зависимости от их веса, возраста и силы.
Нужно сравнить каждый критерий по отдельности, и победителем будет тот, у которого больше "победивших" критериев.
Метод должен определять, выиграли ли мы (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 count;
count = 0;
int count1 = 0;
if (this.age > anotherCat.age)
count++;
else
count1++;
if (this.weight > anotherCat.weight)
count++;
else
count1++;
if (this.strength > anotherCat.strength)
count++;
else
count1++;
if (count > count1)
return true;
else
return false;
}
public static void main(String[] args) {
Cat cat = new Cat();
cat.age = 3;
cat.weight = 5;
cat.strength = 8;
Cat anotherCat = new Cat();
anotherCat.age = 4;
anotherCat.weight = 6;
anotherCat.strength = 9;
System.out.println(cat.fight(anotherCat));
System.out.println(anotherCat.fight(cat));
}
}package com.javarush.task.task05.task0502;
/*
Реализовать метод fight
Реализовать метод boolean fight(Cat anotherCat):
реализовать механизм драки котов в зависимости от их веса, возраста и силы.
Нужно сравнить каждый критерий по отдельности, и победителем будет тот, у которого больше "победивших" критериев.
Метод должен определять, выиграли ли мы (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 count;
count = 0;
int count1 = 0;
if (this.age > anotherCat.age)
count++;
else
count1++;
if (this.weight > anotherCat.weight)
count++;
else
count1++;
if (this.strength > anotherCat.strength)
count++;
else
count1++;
if (count > count1)
return true;
else
return false;
}
public static void main(String[] args) {
Cat cat = new Cat();
cat.age = 3;
cat.weight = 5;
cat.strength = 8;
Cat anotherCat = new Cat();
anotherCat.age = 4;
anotherCat.weight = 6;
anotherCat.strength = 9;
System.out.println(cat.fight(anotherCat));
System.out.println(anotherCat.fight(cat));
}
}