Question: ***Please answer the below question parts using java code*** 1. Write the code to load an array. Use simple I/O (system.out.print, etc.) to get integer

***Please answer the below question parts using java code***

1. Write the 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 (research this) and 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 you did in #2 above now we will 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. *This sounds complex, it is not. Break it down into parts; figure out what needs to be in the try block, 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), and 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!