Answered step by step
Verified Expert Solution
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
(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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started