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 availableFood
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
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
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