Question: Instructions Animal Class Instructions Create two java files: Animal.java AnimalDemo.java Animal Class.java Your Animal class should contain 3 private data members and 6 public methods

Instructions

Animal Class

Instructions

Create two java files:

  1. Animal.java
  2. AnimalDemo.java

Animal Class.java

Your Animal class should contain 3 private data members and 6 public methods as follows...

Data Members:

  • name
  • age
  • species

Methods:

  • getName()
  • setName()
  • getAge()
  • setAge()
  • getSpecies()
  • toString()

The getters and setters should respectively return or update the name, and the toString() method should override Java's built in toString method (which every Java object has), and should display something like this:

Name: Jimmy. Age: 3. Species: Squirrel.

You should also have two constructors for the Animal so that it is possible to initialize a new Animal with default data values of "Unnamed", -1, and "Unknown". The other constructor should take the three values needed to initialize a new Animal object with all three data members.

AnimalDemo.java

The AnimalDemo.java will be a driver class that you will use to demo the Animal class. The driver should initialize two animal objects. One animal should be constructed with its name, age, and species. (You decide those.) The other animal should be constructed with the default values, and subsequently use the setter methods to give the animal a name, age, and species.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!