public class Cat { // Declaration of instance variables. private String name, furType; private boolean tail; private Color colour; private int speed; /** This is the sleep method for the cat. It dictates the number of * minutes the cat sleeps. *
@param duration The number of minutes to sleep. */ public void sleep(int duration) { System.out.println("I am sleeping for " + duration + " minutes."); }public String getname() {return name ; }public Color getcolour() {return colour ; }public int getspeed() {return speed ; } public void setname(String name){this.name=name; } public void setcolor(Color colour){this.colour=colour; } public void setspeed(int speed){this.speed=speed; } /** This method allows the cat to run. The distance (in a straight line) * the cat runs is dependent on how long the cat runs and whether or not * it is running in a zigzag. * @param duration The number of minutes to run. * @param zigzag Whether to run in a zigzag pattern. *
@return int Number of metres ran. */ public int run(int duration, boolean zigzag) { System.out.println("I am running " + (zigzag? "in a zigzag" : "straight") + " for " + duration + " minutes.");int distanceRun = duration * speed; // assuming speed is metres per minuteif (zigzag) { /* When in zigzag, distance is 1/3 of what it would have been if the cat was going straight. */ return distanceRun/3; } else return distanceRun; }}