Question: Demonstrate Recursion and Exception handling Write a small java program to recursively read a file that at first does not exist. Program exception handling that
Demonstrate Recursion and Exception handling
Write a small java program to recursively read a file that at first does not exist.
Program exception handling that allows the user to correct the problem.
Track and display the consecutive number of each recursive call see example output
When the problem is fixed, thank the user ONLY ONCE.
Track the number of recursive returns, unwinding from the count of the deepest return see
example output
Example output:
Failed to open file testData.dat: iostream error
Recursive call count:
Please remedy the situation. Then press enter to continue.
Failed to open file testData.dat: iostream error
Recursive call count:
Please remedy the situation. Then press enter to continue.
Failed to open file testData.dat: iostream error
Recursive call count:
Please remedy the situation. Then press enter to continue.
Failed to open file testData.dat: iostream error
Recursive call count:
Please remedy the situation. Then press enter to continue.
Failed to open file testData.dat: iostream error
Recursive call count:
Please remedy the situation. Then press enter to continue.
Failed to open file testData.dat: iostream error
Recursive call count:
Please remedy the situation. Then press enter to continue.
Failed to open file testData.dat: iostream error
Recursive call count:
Please remedy the situation. Then press enter to continue.
Failed to open file testData.dat: iostream error
Recursive call count:
Please remedy the situation. Then press enter to continue.
Thanks for fixing that.
Recursion return count:
Recursion return count:
Recursion return count:
Recursion return count:
Recursion return count:
Recursion return count:
Recursion return count:
Recursion return count:
This is the content of the file:
Howard, Shemp
Howard, Moe
Fine, Larry
Howard, Curly
Process returned x execution time : s
Press any key to continue.
My Solution:
I did this in one file with functionsmethods
bool fileOpenifstream inFile, int count RECURSIVE CALLS TO THIS
inFile is the name of the file to open.
count is the recursion count bump this number for each call to this functionmethod
Returns true if this is the first return. In other words, the last call to this functionmethod
where the user fixes the problem.
The trythrow catch exception handling is completely contained in this functionmethod
Recursive call counts are adjusted here.
Use getline in c to just press enter to continue
The return Boolean value is used to determine when to print the one time message thanking the
user for fixing the problem.
void readDataFile
Initial the count and call fileOpen When this call returns, any file existence problems will have
been resolved.
Step through all the file records and display them.
Dont forget to close the file.
main
Simply call readDataFile.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
