Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is for java programming. Please answer all the parts for number 8 only and explain well so that I may understand. Thank you. In

This is for java programming. Please answer all the parts for number 8 only and explain well so that I may understand. Thank you.

image text in transcribedimage text in transcribed

In the loop example below tick() is used since the method relates to the virtual passing of time. While in this case all that happens is the hunger level increases other simulators might have much more complex effects. public static void main(String[] args) { ArrayList farm = new ArrayList(); for (Animal animal: farm) { animal.tick(); animal.feed(); System.out.println(animal.speak()); System.out.println(animal); 7. When printed an animal should indicate. The animal's name, the type of the animal and the animal's hunger level: Ely the cow is very hungry. 8. If we are never going to instantiate an Animal directly what type of class could we make it? Explain. Put your answer in the comments at the bottom of your report. Note: It is possible that when you run the simulation it will loop infinitely*. Can you explain why? Put your answer in the comments at the bottom of your report * For larger sets of animals this would almost always happen. You could put this in the constructor: hungerUnits = hungerUnits-(hungerUnits%5); What does this do? Why does this stop infinite loops? In the loop example below tick() is used since the method relates to the virtual passing of time. While in this case all that happens is the hunger level increases other simulators might have much more complex effects. public static void main(String[] args) { ArrayList farm = new ArrayList(); for (Animal animal: farm) { animal.tick(); animal.feed(); System.out.println(animal.speak()); System.out.println(animal); 7. When printed an animal should indicate. The animal's name, the type of the animal and the animal's hunger level: Ely the cow is very hungry. 8. If we are never going to instantiate an Animal directly what type of class could we make it? Explain. Put your answer in the comments at the bottom of your report. Note: It is possible that when you run the simulation it will loop infinitely*. Can you explain why? Put your answer in the comments at the bottom of your report * For larger sets of animals this would almost always happen. You could put this in the constructor: hungerUnits = hungerUnits-(hungerUnits%5); What does this do? Why does this stop infinite loops

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Successful Keyword Searching Initiating Research On Popular Topics Using Electronic Databases

Authors: Randall MacDonald, Susan MacDonald

1st Edition

0313306761, 978-0313306761

More Books

Students also viewed these Databases questions