Question: (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

 (B) Update the FarmTestclass with the code given belovw Farm myFarmnew

(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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!