Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create an Animal class that stores information about an Animal: Name, age, weigh

ID: 3641852 • Letter: C

Question

Create an Animal class that stores information about an Animal: Name, age, weight and contains the following methods:
A constructor that sets the parameters of the class
Setters and getters (Accessors and Mutators)
A toString method that prints the animal information
An eat method that doesn't have anything defined in it
A run method that prints the name of the animal running (example: Casey is running)
Create two derived classes: Dog and Cat. In the Cat class (resp. Dog class), put a static member that stores the number of cats (resp. dogs) ever created respectively.
In each of the derived classes implement the following methods:
A constructor that sets the parameters of the class (Use the super constroctor to set the common parameters)
Override the toString method that prints the animal information. Example: (Casey the dog, age: 5, weight: 20)
Override the eat method to print the name of the cat eating fish and the name of the dog eating a bone (example: Casey eating a bone)


this is what i have so far

public class AnimalLab
{
private String myName;
private int myAge;
private int myWeight;

public AnimalLab()
{

}
//constructor that sets paramets
public AnimalLab(String n, int a, int w)
{
myName = n;
myWeight = w;
myAge = a;
}

//eat method
public void eat()
{

}

//run method
public void run()
{
System.out.println(myName + " is running");
}

// setters
public void setN( String n)
{
myName = n;
}
public void setW( int w)
{
myWeight= w;
}
public void setA( int a)
{
myAge = a;
}

//getters
public String getN () {return myName;}
public int getW () {return myWeight;}
public int getA () {return myAge;}
}

then my cat/ dog class looks like
public class dog extends AnimalLab
{
public dog (String n, int a, int w)
{
super (n, a, w);
}

public void run ()
{

}

public void eat (String bone)
{
System.out.println( +n " is eating a bone");
}
}

Explanation / Answer

Please run the AnimalImpl.java class to display the information. AnimalImpl Class ********************* package animal; public class AnimalImpl { public static void main(String args[]) { AnimalLab animalLab = new AnimalLab("Horse",2,6); animalLab.run(); Cat cat = new Cat("pussy",2,6); cat.eat(); cat.run(); Dog dog = new Dog("Caeser",5,30); dog.run(); dog.eat(); } } ******************************************************************************************** Animal Class ********************* package animal; public class AnimalLab { private String myName; public String getMyName() { return myName; } public void setMyName(String myName) { this.myName = myName; } public int getMyAge() { return myAge; } public void setMyAge(int myAge) { this.myAge = myAge; } public int getMyWeight() { return myWeight; } public void setMyWeight(int myWeight) { this.myWeight = myWeight; } private int myAge; private int myWeight; public AnimalLab() { } // constructor that sets paramets public AnimalLab(String n, int a, int w) { this.myName = n; this.myWeight = w; this.myAge = a; } // eat method public void eat() { } // run method public void run() { System.out.println(getMyName() + " is running"); } public String toStirng(){ return myName+" the dog, age: "+ myAge+ ", weight: "+myWeight; } } **************************************************************************************************** Dog Class ********************* package animal; public class Dog extends AnimalLab { public Dog(String n, int a, int w) { super(n, a, w); } public void run() { } public void eat() { System.out.println(getMyName()+ " is eating a bone"); } } **************************************************************************************************** Cat.java ********************* package animal; public class Cat extends AnimalLab { String n; int a; int w; public Cat(String n, int a, int w) { super(n, a, w); } public void run() { } public void eat() { System.out.println(getMyName() + " is eating a fish"); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote