Question: This is a Java question; I want to write a method that reads a file and throws exceptions, example here is a good data text.
This is a Java question;
I want to write a method that reads a file and throws exceptions,
example here is a good data text.
6 5 s . . . . . . b . . . . . . . b b . . . . . . . b . . . . . 4 2 3 0 1 2
where it represents for,
6 5 // rows and cols s . . . . // maze with cheese mouse postion at (0,0) . . b . . . . . . . b b . . . . . . . b . . . . . 4 // number of boxes 2 // number of cheese 3 0 // cheese at (3,0) and (1,2) 1 2
The method should throw an IOException with an appropriate message if the data is not valid. Special exception messages include:
The file specified was not found Bad dimensions for the grid Inaccurate number of rows of data to read Inaccurate number of columns of data to read
for bad inputs
Sample output 1 Input file: s . . b 1 1 1 1
Exception Thrown: java.io.IOException: No dimension to read Sample output 2 Input file: 2 2 s . . b 1 1
Exception Thrown: java.io.IOException: Inaccurate number of rows of cheese positions in the file. Saw 0 expected 1 Sample output 3 Input file:
4 5 s . . . . b . . . . . . 1 1 1 1
Exception Thrown: java.io.IOException: Inaccurate number of columns of cheese in the file. Saw 4 expected 5
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
