MAIN
package com.cnc;
public class Main {
public static void main(String[] args) {
Animal animal = new Animal("Animal",1,1,5,5);
Dog dog = new Dog("YorkE",8,20,2,4,1,20,"Silky Hair");
dog.eat();
dog.walk();
dog.run();
}
}
1 ANIMALS
package com.cnc;
public class Animal {
private String name;
private int brain;
private int body;
private int size;
private int weight;
public Animal(String name, int brain, int body, int size, int weight) {
this.name = name;
this.brain = brain;
this.body = body;
this.size = size;
this.weight = weight;
}
public void eat(){
System.out.println("Animal is eating");
}
public void move(int speed){
System.out.println("Animal is moving at "+speed);
}
public String getName() {
return name;
}
public int getBrain() {
return brain;
}
public int getBody() {
return body;
}
public int getSize() {
return size;
}
public int getWeight() {
return weight;
}
}
2 DOG
package com.cnc;
public class Dog extends Animal{
// dogs have this class this characteristics in addition to
// the default animal class
private int eyes;
private int legs;
private int tail;
private int teeth;
private String coat;
public Dog(String name, int size, int weight, int eyes, int legs,int tail,int teeth, String coat) {
super(name, 1, 1, size, weight);
this.eyes = eyes;
this.legs = legs;
this.tail = tail;
this.teeth = teeth;
this.coat = coat;
}
private void chew(){
System.out.println("Dog.chew() called");
}
// OVERRIDE
public void eat(){
System.out.println("Dog.eat() called");
chew();
super.eat();
}
public void walk(){
System.out.println("Dog.walk() called");
move(5);
}
public void run(){
System.out.println("Dog.run() called");
move(10);
}
}
3 FISH
package com.cnc;
public class Fish extends Animal {
private int gills;
private int eyes;
private int fins;
public Fish(String name, int size, int weight, int gills, int eyes, int fins) {
super(name, 1, 1, size, weight);
this.gills = gills;
this.eyes = eyes;
this.fins = fins;
}
private void rest(){
}
private void moveMuscles(){
}
private void moveBackFin(){
}
private void swim(){
}
private void swim(int speed){
moveBackFin();
moveMuscles();
super.move(speed);
}
}