Hi. The program does not pass this code. It says me that something is wrong with the weight in the 'Fight' method implementation. I'm not able to see the error. Please, could somebody help me. Thank you very much.
package com.codegym.task.task05.task0502;
/*
Implement the fight method
*/
public class Cat {
public int age;
public int weight;
public int strength;
public Cat() {
}
//setters
public void setAge(int age){
this.age = age;
}
public void setWeight(int weight){
this.weight = weight;
}
public void setStrength(int strength){
this.strength = strength;
}
//getters
public int getAge(){
return this.age;
}
public int getWeight(){
return this.weight;
}
public int getStrength(){
return this.strength;
}
public boolean fight(Cat anotherCat) {
//write your code here
int cat1Total = this.getAge() + this.getWeight() + this.getStrength();
int cat2Total = anotherCat.getAge() + anotherCat.getWeight() + anotherCat.getStrength();
//System.out.println("Total cat1: " + cat1Total);
//System.out.println("Total cat2: " + cat2Total);
if (this.getAge() - this.getWeight() + this.getStrength() > anotherCat.getAge() - anotherCat.getWeight() + anotherCat.getStrength())
return true;
else
return false;
}
public static void main(String[] args) {
Cat cat1 = new Cat();
cat1.setAge(12);
cat1.setWeight(11);
cat1.setStrength(10);
Cat cat2 = new Cat();
cat2.setAge(11);
cat2.setWeight(15);
cat2.setStrength(8);
Boolean b = cat1.fight(cat2);
/*if (b){
System.out.println("Si cat1 pelea contra cat2 Gana cat1");
if (!(cat2.fight(cat1)))
System.out.println("Si cat2 pelea contra cat1 Gana cat1 igualmente");
}*/
}
}