public class Cat {
public int age;
public int weight;
public int strength;
public Cat() {
}
public boolean fight(Cat anotherCat) {
//write your code here
if( this.age > anotherCat.age && this.strength > anotherCat.strength && this.weight > anotherCat.weight)
return true;
else
return false;
}
public static void main(String[] args) {
Cat cat1 = new Cat();
Cat cat2 = new Cat();
cat1.weight = 15;
cat1.age = 4;
cat1.strength = 30;
cat2.weight = 15;
cat2.age = 4;
cat2.strength = 30;
System.out.println(cat1.fight(cat2));
System.out.println(cat2.fight(cat1));
}
}
I'm trying to pass this exercise however will not let me pass the last statement, if you can please show me where I made a mistake and explain.
Under discussion
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
null
8 October 2019, 20:20
your fight condition only returns true only if THREE of the variables of cat1 > cat2. since they are all equal it will return false. Just needa lower all the cat2's variables.
0
Raj Mishra Java Developer at Sopra banking softwa
5 October 2019, 18:16
What if the strength , age and weight are equal. Both will be false
0