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 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
Get step-by-step solutions from verified subject matter experts
