1. Не понимаю сама задача, зачем мне пустой конструктор или его нет по умолчанию?
2.В методе fight реализовать механизм драки котов в зависимости от их веса, возраста и силы согласно условию.->
Тест, который я уже провел с конструкцией if i else if, не так ли?
3.Если некий кот1 выигрывает у кота кот2, то кот2 должен проигрывать коту кот1.
Тест, который я уже провел с конструкцией if i else if, не так ли?
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) {
int victoryPointsCat= 0;
int victoryPointsAnotherCat = 0;
int nooneWins = 0;
if(age>anotherCat.age){
victoryPointsCat += victoryPointsCat;
} else if (age<anotherCat.age){
victoryPointsAnotherCat+=victoryPointsAnotherCat;
}else{
nooneWins +=nooneWins;
}
if(weight>anotherCat.weight){
victoryPointsCat +=victoryPointsCat;
} else if (weight<anotherCat.weight){
victoryPointsAnotherCat +=victoryPointsAnotherCat;
}else{
nooneWins +=nooneWins;
}
if(strength>anotherCat.strength){
victoryPointsCat +=victoryPointsCat;
}else if ( strength<anotherCat.strength){
victoryPointsAnotherCat+=victoryPointsAnotherCat;
}else{
nooneWins +=nooneWins;
}
if (victoryPointsCat>victoryPointsAnotherCat){
return true;
} else {
return false;
}
}
public static void main(String[] args) {
Cat cat = new Cat();
Cat cat2 = new Cat();
cat.age = 1;
cat2.age = 5;
cat.strength = 2;
cat2.strength = 4;
cat.weight = 3;
cat2.weight = 5;
cat.fight(cat2);
System.out.println(cat.fight(cat2));
}
}