Question
Please help me make this run correctly. It is a Java program: Animal.java public abstract class Animal extends Object{ private String name; public abstract void
Please help me make this run correctly. It is a Java program:
Animal.java
public abstract class Animal extends Object{
private String name;
public abstract void move();
public String toString() {
return \"Animal\" + name + \" \";
}
}
Reptile.java
public abstract class Reptile extends Animal{
public Reptile(String name){
super(name);
}
public abstract void move();
public String toString() {
return super.toString() + \"of reptile subspecies\";
}
}
Mammal.java
public abstract class Mammal extends Animal{
public Mammal(String name){
super(name);
}
public abstract void move();
public String toString() {
return super.toString() + \"of mammal subspecies\";
}
}
Cow.java
class Cow extends Mammal{
public Cow(String name){
super(name);
}
@Override
public void move(){
System.out.println(\"Its mobility is trotting.\");
}
@Override
public String toString() {
return super.toString() + \" is a cow.\";
}
}
Dog.java
class Dog extends Mammal{
public Dog(String name){
super(name);
}
@Override
public void move(){
System.out.println(\"It can run.\");
}
@Override
public String toString() {
return super.toString() + \" is a dog.\";
}
}
Turtle.java
class Turtle extends Reptile{
public Turtle(String name){
super(name);
}
@Override
public void move(){
System.out.println(\"It can swim.\");
}
@Override
public String toString() {
return super.toString() + \" is a turtle.\";
}
}
Snake.java
class Snake extends Reptile{
public Snake(String name){
super(name);
}
@Override
public void move(){
System.out.println(\"It's mobility is slithering.\");
}
@Override
public String toString() {
return super.toString() + \" is a snake.\";
}
}
TestAnimals.java
class Animal extends Object{
public static void main(String[] args) {
Dog dogMammal = new Dog(\"Murphy\");
Cow cowMammal = new Cow(\"Daisy\");
Turtle turtleReptile = new Turtle(\"Speedy\");
Snake snakeReptile = new Snake(\"Sammy\");
System.out.print(dogMammal);
System.out.print(cowMammal);
System.out.print(turtleReptile);
System.out.print(snakeReptile);
}
}
Expected output:
1. Create a TestAnimals Class to test the Animal class and subclasses In the TestAnimals, create 4 objects: Murphy a dog (Mammal) Daisy a Cow (Mammal) Speedy a turtle (Reptile) Sammy a snake (Reptile) 2. Implement mobility correctly for each subclass 3. Out put of TestAnimals Class below Animal Murphy of mammal subspecies is a dog. It can run. Animal Daisy of mammal subspecies is a cow. Its mobility is trotting. Animal Speedy of reptile subspecies is a turtle. It can swim. Animal Sammy of reptile subspecies is a snake. Its mobility is slithering.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started