Question: ***Please use Java code to create the program based on requirements below*** 1: Write java code to load an array. Use simple I/O (system.out.print, etc.)
***Please use Java code to create the program based on requirements below***
1: Write java code to load an array. Use simple I/O (system.out.print, etc.) to get integer values from the user and load the array (loop?).
Your code has the potential to generate 2 exceptions:
1) InputMismatch
2) IllegalValueException (assume this exists).
If the 1st occurs, change the input to be 99, warn the user and continue.
The 2nd exception will occur when the user enters a 0; if this occurs, notify the user that a 0 has been entered, and change the input to -99.
2: Take the code created in #2 above now load the array with data from a file.
The file is in the same directory as the program file and is called data.txt. Create the File and the Reader objects now you have to worry about a FileNotFoundException (just print the error message).
You must also adjust the handling of the InputMismatch (load the array with all 0s) and IllegalValueException (load the array with all 1s).
If the file was opened at all, ensure it is closed whether you had an exception or not. Write the code to load the data, then handle each catch block separately
3: Create a method (called DataSave) that will write data to a file. This method will accept an array of Person objects.
The method will open the file (data.txt), and place each person object information (from the array) into the file (1 per line).
Data items you are putting into each line of the file are:
FName (string)
LName (string)
age (int)
married status (boolean).
** You may assume there are appropriate get methods for your use.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
