subject

SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA. Assume that the classes listed in the Java Quick Reference have been imported where appropriate.
Unless otherwise noted in the question, assume that parameters in method calls are not null and that methods are called only when their preconditions are satisfied.
In writing solutions for each question, you may use any of the accessible methods that are listed in classes defined in that question. Writing significant amounts of code that can be replaced by a call to one of these methods will not receive full credit.

A set of classes using inheritance is used to represent animals observed at a wildlife sanctuary. A portion of the class hierarchy is shown in the following diagram.
The figure presents a diagram of a class hierarchy with three levels. The highest level has one class labeled Animal. The middle level has two classes labeled Carnivore and Herbivore. The lowest level has one class labeled Elephant. Three arrows are drawn: one from Elephant to Herbivore, one from Herbivore to Animal, and one from Carnivore to Animal.

All Animal objects have the following attributes.

A String variable indicating whether the animal is a carnivore or a herbivore
A String variable representing the animal species (e. g., lion, giraffe, zebra)
A String variable representing the name of the individual animal (e. g., Lisa, Gary, Percy)

The Animal class also contains a toString method that indicates the state of an animal.

The following table shows the intended behavior of the Animal class.
Statement Result
Animal lisa = new Animal("carnivore", "lion", "Lisa"); A new Animal object is created.
lisa. toString(); The string "Lisa the lion is a carnivore" is returned.

(a) Write the complete Animal class. Your implementation must meet all specifications and conform to the behavior shown in the table.

The Herbivore class is a subclass of Animal. The Herbivore class does not contain any attributes or methods other than those found in the Animal class.

The constructor to the Herbivore class accepts two parameters for the species and name of the herbivore. The constructor passes those parameters along with the string literal "herbivore" to the Animal class to construct the object.

The following table shows the intended behavior of the Herbivore class.
Statement Result
Herbivore gary = new Herbivore("giraffe", "Gary"); A new Herbivore object is created.
gary. toString(); The string "Gary the giraffe is aherbivore" is returned.

(b) Write the complete Herbivore class. Your implementation must meet all specifications and conform to the behavior shown in the table.

The Elephant class is a subclass of Herbivore. The Elephant class contains one additional attribute not found in Herbivore: a double variable representing the length of the elephant’s tusks, in meters.

The constructor to the Elephant class accepts two parameters for the name and tusk length of the elephant. The constructor passes those parameters along with the string literal "elephant" to the Herbivore class to construct the object.

The following table shows the intended behavior of the Elephant class.
Statement Result
Elephant percy = new Elephant("Percy", 2.0); A new Elephant object is created.
percy. toString(); The string "Percy the elephant is aherbivore with tusks 2.0 meters long" is returned.

(c) Write the complete Elephant class. Your implementation must meet all specifications and conform to the behavior shown in the table.

ansver
Answers: 2

Another question on Advanced Placement (AP)

question
Advanced Placement (AP), 23.06.2019 19:30
Sheri likes to study in the school library, but it is usually full of chatting students. it's a great place to study because her friends can always drop by when they want to talk to her. sheri should seek a new study space with a. more light c. less distractions b. less people d. more access to a restroom select the best answer from the choices provided a b c d
Answers: 1
question
Advanced Placement (AP), 25.06.2019 19:40
What are 3 traits that ruth may price has in the poisonwood bible? how has she adapted to the new situation? what effect has she had on others?
Answers: 2
question
Advanced Placement (AP), 26.06.2019 00:30
What is the american psychological association’s ethical principle of psychologists and code of conduct based upon? a. the work of a dozen world-renowned philosophers and ethical savants. b. the feedback of thousands of psychologists and their ethical struggles. c. the regulatory power and authority of the united states constitution. d. the hippocratic rules and guidelines of medical practitioners and surgeons. select the best answer from the choices provided a b c
Answers: 1
question
Advanced Placement (AP), 26.06.2019 01:00
In your own words define the following terms. 1 hibernation. 2 hormone. 3 behavior. 4 stimulus
Answers: 1
You know the right answer?
SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA. Assume that the clas...
Questions
question
History, 05.02.2020 02:48
question
Mathematics, 05.02.2020 02:48
question
Mathematics, 05.02.2020 02:48
question
Social Studies, 05.02.2020 02:48
question
Mathematics, 05.02.2020 02:48