Question: o Add a method void exit (String filename) +4] The method saves the farm data to a file named filename. Farm data includes at least
![o Add a method void exit (String filename) +4] The method](https://s3.amazonaws.com/si.experts.images/answers/2024/09/66e07271eee72_39366e0727154aa2.jpg)
o Add a method void exit (String filename) +4] The method saves the farm data to a file named filename. Farm data includes at least availableFood and animals (i.e. the array with all animal instances) [+1] Once saved, display a message that data was saved successfully [+4] If errors (exceptions) happen during the saving process, the method should print an error message. You should have at least two catch statements (one of them is FileNotFoundException) [+1] Make sure your code closes the output stream regardless of whether an error happens or not. [+2] Implement any required changes in your code (e.g. in other classes) so that this method works . . o Add a method void load (String filename) +4] The method loads the farm data from a file named filename. . [+1] Once loaded, display a message that data was load successfully. . [+3] If errors (exceptions) happen during the loading process, the method should print an error message. You should have at least three catch statements (one of them is FileNotFoundException) [+4] If filename is not found: in addition to the error message from the above bullet initialize the game with default values, e.g. availableFood should be 1000, animals array should have 100 spots and 4 animals: a chicken, a cow, and 2 llamas. . . [+1] Make sure your code closes the output stream regardless of whether an error happens or not. o Add a method void exit (String filename) +4] The method saves the farm data to a file named filename. Farm data includes at least availableFood and animals (i.e. the array with all animal instances) [+1] Once saved, display a message that data was saved successfully [+4] If errors (exceptions) happen during the saving process, the method should print an error message. You should have at least two catch statements (one of them is FileNotFoundException) [+1] Make sure your code closes the output stream regardless of whether an error happens or not. [+2] Implement any required changes in your code (e.g. in other classes) so that this method works . . o Add a method void load (String filename) +4] The method loads the farm data from a file named filename. . [+1] Once loaded, display a message that data was load successfully. . [+3] If errors (exceptions) happen during the loading process, the method should print an error message. You should have at least three catch statements (one of them is FileNotFoundException) [+4] If filename is not found: in addition to the error message from the above bullet initialize the game with default values, e.g. availableFood should be 1000, animals array should have 100 spots and 4 animals: a chicken, a cow, and 2 llamas. . . [+1] Make sure your code closes the output stream regardless of whether an error happens or not
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
