Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(B) Update the FarmTestclass with the code given belovw Farm myFarmnew Farm (stat.dat); myFarm.printSummary (); for (Animal a: myFarm.getAnimals ()) a.setEnergy (Math.random ) 100); System.out.println

image text in transcribed

(B) Update the FarmTestclass with the code given belovw Farm myFarmnew Farm ("stat.dat"); myFarm.printSummary (); for (Animal a: myFarm.getAnimals ()) a.setEnergy (Math.random ) 100); System.out.println (" nAvailable food before feeding: " + myFarm.getAvailableFood +"n") System.out.println(" Initial list of animals: ----") myFarm.printAnimals(); System.out.println(" Adding a clone of the second animalln--" myFarm.addClone (myFarm.getAnimals) [1]) myFarm.printAnimals (); myFarm. feedAnimals (); System.out.println(" nAvailable food after feeding: "+ myFarm.getAvailableFood + " ") System.out.println(" After SORTING: In-" myFarm.animSort (); myFarm.printAnimals () System.out.println(" Farm summary: --- myFarm.printSummary (); myFarm.exit("stat.dat"); Above code should print an output similar to the one on the next page. Note that this output may be slightly different based on several factors such as your animals' energy and the available food in the farm (C) Run FarmTest multiple times and notice how the number of animals increases. Explain why this happens? (write your answer as a comment in FarmTest class) (B) Update the FarmTestclass with the code given belovw Farm myFarmnew Farm ("stat.dat"); myFarm.printSummary (); for (Animal a: myFarm.getAnimals ()) a.setEnergy (Math.random ) 100); System.out.println (" nAvailable food before feeding: " + myFarm.getAvailableFood +"n") System.out.println(" Initial list of animals: ----") myFarm.printAnimals(); System.out.println(" Adding a clone of the second animalln--" myFarm.addClone (myFarm.getAnimals) [1]) myFarm.printAnimals (); myFarm. feedAnimals (); System.out.println(" nAvailable food after feeding: "+ myFarm.getAvailableFood + " ") System.out.println(" After SORTING: In-" myFarm.animSort (); myFarm.printAnimals () System.out.println(" Farm summary: --- myFarm.printSummary (); myFarm.exit("stat.dat"); Above code should print an output similar to the one on the next page. Note that this output may be slightly different based on several factors such as your animals' energy and the available food in the farm (C) Run FarmTest multiple times and notice how the number of animals increases. Explain why this happens? (write your answer as a comment in FarmTest class)

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