Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Write a report on a universal motor. ( no more than 3 pages )

Answered: 1 week ago