In this assignment, you will use recursion, file manipulation, and exceptions.

You are to improve upon the Nonogram solution (zip file attached). Familiarize yourself with the Scanner, File and Paths classes and the Path interface as they will come in handy.

Modify the Nonogram solution as follows:

1. Check for errors in each data file. The current code assumes no errors in formatting and no errors in the characters themselves. Errors include: (1) data not formatted correctly such as incorrect number of rows and columns in the file, and (2) invalid characters (e.g., "8", "A", or "$").

Define at least two different types of Exception classes (your own custom-made) and throw/catch exceptions as necessary. For example:

You will notice that the files are read in Puzzle's constructor. If these are not 0 nor 1, throw an appropriate exception. Secondly, count the number of 0s and 1s on each line and the number of lines. If there are too many or too few in either direction, throw another appropriate exception.

When an exception is encountered, the program must send an Alert(dialog or pop-up) window indicating the problem. An example of Alert usage:

Alert alert = new Alert(AlertType.ERROR, errorMessage, ButtonType.OK);
alert.showAndWait();

where errorMessage is a String containing the message to show in the dialog. The Alert message should be as precise as possible (e.g., "Problem encountered" would not make a precise message). After the Alert window is closed, the code should not abort but continue to attempt to load another puzzle. The program should not crash because of errors in the text files.

2. Check each subfolder for data files. Currently, the code looks for puzzles in the Data subfolder (a.k.a. subdirectory) . You are to change this so that it will not only check the Data subfolder but also every sub-subfolder within Data, and every sub-sub-subfolder, etc. until there are no more folders in each folder. Each of the .txt files found is then added to the pool of puzzles. This has to be done recursively as we do not know ahead of time how many levels deep these subfolders are structured. This is currently done in PuzzlePool's loadFiles method. You may consider adding a private, recursive, helper method.

3. The method signatures (headers) in Puzzle and PuzzlePool should not change. However, you may add instance data if absolutely necessary. The Controller class should not change other than for superficial color changes and additional Help and About features.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.