Есть класс Animal
и сабкласс Cat
, хочу, чтоб Cat
принимал имя и ограничение на максимальное расстояние для бега.
Но созданный метод выводит всегда результат "бежит" при любом отрицательном параметре расстояния и "не может бежать" при любом положительном параметре. Не пойму, как исправить?
Класс Animal:
public class Animal {
protected String name;
protected boolean canRun = true;
protected boolean canSwim = true;
protected boolean canJump = true;
protected int maxRunLength;
protected double maxJumpHeigth;
protected int maxSwimLength;
protected int length;
protected double jump;
public Animal(){
}
public Animal(String name) {
this.name = name;
}
public void run(int length) {
if (length <= this.maxRunLength) {
System.out.println(this.name + " is running");
} else {
System.out.println("can`t run");
}
}
}
Класс Cat:
public class Cat extends Animal {
protected int maxRunLength;
protected double maxJumpHeigth = 2;
protected boolean canSwim = false;
public Cat(){
}
public Cat(String name, int maxRunLength) {
this.name = name;
this.maxRunLength = maxRunLength;
}
}