Question
I need some help please! I'm working with java programming and I need to create one of each type of animal and displays the animals
I need some help please! I'm working with java programming and I need to create one of each type of animal and displays the animals toString method. You are to add the following: - Animals have a Weight. - Animals have a Height. - Dog is an Animal. - Dogs have a Name. - Dogs have a Breed. - Dogs have a DOB. - Cat is an Animal - Cats have a Name. - Cats have 9 lives, so you need to keep track of the remaining lives once a cat dies. - Bird is an Animal - Birds have a wing span - Birds have a canFly (some birds cannot fly) PLEASE SEND SCREEN SHOTS OF THE ECLIPSE WORKSPACE.
Here is my code. It won't run!
import java.io.*; import java.util.*;
class Animal // Create a Base Class name Animal { double height,weight; // Declare two variables height and weight String name; // Declare Name of the Animal public void setName(String name) // Define setter function for Name of the Animals which is defined to different derived classes(Dog,Cat and Birds) { this.name=name; // assign name is using "this" pointer } public String getName() // Define getter function for Name which is access to different derived Classes(Dog,Cat and Birds) { return name; } public void setHeight(double height) // Define setter function for Height of the Animals(Dog,Cat,Birds) { this.height=height; } public void setWeight(double weight) // Define setter function for Weight of the Animals(Dog,Cat,Birds) { this.weight=weight; } public double getHeight() // Define getter fuction for Height of the Animals(Dog,Cat,Birds) { return height; } public double getWeight() // Define getter function for Weight of the Animals(Dog,Cat,Birds) { return weight; } }
public class Dog { String breed,DOB; // Declare two String variables breed and Date of Birth of Dog(DOB) public void setDog(String breed,String DOB) // Define Setter Function for Dog variables {
this.breed=breed; this.DOB=DOB; // assign using "this" pointer }
public String getDogBreed() // Define getter function for access Breed of Dog { return breed; } public String getDogDOB() // Define getter function for access DOB of Dog { return DOB; } }
public class Cat {
int lives=9; // Declare Integer varibale lives and initialize number of lives 9
public int getCatLives() // Define getter function for Number of Lives of the Cat it could be decrement by 1
{
return lives-1;
}
}
public class Birds {
int wings,fly; // Declare two Integer varibale wings and fly
public void setWings(int wings) // Define Setter function for wings
{
this.wings=wings;
}
public void setFly(int fly) // Define setter function for fly of birds
{
this.fly=fly;
}
public boolean getFly() // Define boolean function for which is bird is fly or not
{
if(fly==1) return true; // if the bird is fly the return true else false
else
return false;
}
public int getWings() // Define getter function for number of wings
{
return wings;
}
}
public class TestAnimals {
public static void main(String args[])
{
Dog d=new Dog(); // Create Object of Dog is d
Cat c=new Cat(); // Create Object of Cat is c
Birds b=new Birds(); // Create Object of Birds is b
System.out.println("Dog Class Information ");
d.setWeight(30.3); // Inherite from Animal property method is setWeight() into the Dog Class
d.setHeight(60.5); // Inherite from Animal property method is setHeight() into the Dog Class
d.setName("Canis"); // Inherite from Animal property method is setName() into the Dog Class
d.setDog("Akita","12-05-2012"); // call the setDog() from the Dog class
System.out.println("Dog Name: "+ d.getName().toString()); //Inherite from Animal property method is getName() into the Dog Class and access using toString() method
System.out.println("Dog Breed: "+d.getDogBreed().toString()); // call the getDogBreed() from the Dog class
System.out.println("Dog DOB: "+ d.getDogDOB().toString()); // call the getDogDOB() from the Dog class
System.out.println("Dog Weight: "+d.getWeight()); // Inherite from Animal property method is getWeight() into the Dog Class
System.out.println("Dog Height: "+d.getHeight()); // Inherite from Animal property method is getHeight() into the Dog Class
c.setWeight(14.5); // Inherite from Animal property method is setWeight() into the Cat Class
c.setHeight(4.3); // Inherite from Animal property method is setHeight() into the Cat Class
System.out.println(" Cat Class Information ");
c.setName("xxx"); // Inherite from Animal property method is setName() into the Cat Class
System.out.println("Cat Name: "+c.getName().toString());//Inherite from Animal property method is getName() into the Cat Class and access using toString() method
System.out.println("Cat Weight: "+c.getWeight());// Inherite from Animal property method is getWeight() into the Cat Class
System.out.println("Cat Height: "+c.getHeight());// Inherite from Animal property method is getHeight() into the Cat Class
System.out.println("Cat No. of Lives: "+c.getCatLives()); // call the getCatLives() from the Cat class it return true or false
b.setWeight(3.24); // Inherite from Animal property method is setWeight() into the Birds Class
b.setHeight(1.33); // Inherite from Animal property method is setHeight() into the Birds Class
b.setName("Parrot"); // Inherite from Animal property method is setName() into the Birds Class
b.setWings(2); //call the setWings() method from the Birds Class
b.setFly(1); // call the setFly() method from the Birds Class
System.out.println(" Bird Class Information ");
System.out.println("Bird Name: "+b.getName().toString()); //Inherite from Animal property method is getName() into the Birds Class and access using toString() method
System.out.println("Bird Weight: "+b.getWeight());// Inherite from Animal property method is getWeight() into the Birds Class
System.out.println("Bird Height: "+b.getHeight());// Inherite from Animal property method is getHeight() into the Birds Class
System.out.println("Bird Wings: "+b.getWings()); // call the getWings() method from Birds Class and return integer value
System.out.println("Bird Fly: "+b.getFly()); // class the getFly() method from Birds Class and return true of false
}
}
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