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

Other questions on the subject: Advanced Placement (AP)

image
Advanced Placement (AP), 25.06.2019 05:30, mcfancei
The probability of rolling a sum of 7 when rolling two dice simultaneously is 0.167. you decide to test that probability by rolling th dice 12 times. what is the probability that exactly 2 of the rolls is a sum of 7?
Answers: 1
image
Advanced Placement (AP), 25.06.2019 17:30, valencial0917
Identify one similarity between china and europe that explains their decisions on wether to explore or conquer lands around the indian ocean
Answers: 1
image
Advanced Placement (AP), 25.06.2019 19:30, jamayeah02
In 2009, roughly of people age 12 or older who did not drink alcohol were current users of illegal drugs. a. 4% b. 10% c. 13% d. 20%
Answers: 1
image
Advanced Placement (AP), 26.06.2019 12:00, ambercable3
20 pts i don't really get this xd1. what is the function in humans of the protein produced from that gene2. would you expect to find the same protein in other organisms? if so, which ones? 3. is it possible to find the same gene in two diff. kinds of organisms4. if you found the same gene in all organisms you test, what does this esuggest about the evolution of this gene in the history of life on earth? 5. does the use of dna sequences in the study of evolutionary relationships mean that other characteristics are unimportant in such studies? explain your answer. what am i supposed to do here
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 in other subjects:

Konu
Computers and Technology, 28.11.2020 18:30
Konu
Mathematics, 28.11.2020 18:30