In this assignment, you will practice using 2-D arrays and applying loops and conditionals.

1. To start, familiarize yourself with how Nonograms work such as this one on Goobix. A video showing your sample Nonogram code running is also available.

2. A starter project is provided: Nonogram.zip, as well as this Nonogram API for the intended code. The starter code does not compile yet! You need to complete the steps below.

  • Install Scene Builder if you have not done that. I have found this YouTube video helpful.
  • Unzip the start project.
  • Check out the text files in the Data subfolder. Notice how the contents of files are formatted.
  • Familiarize yourself with the layout of the classes in the starter code. There is one FXML file and four classes. All classes are complete except for class Puzzle.

1. sample.fxml is the FXML file for the GUI. You do not need to edit this file.

2. Main.java is where the execution starts.

  • Edit the title of the primaryStage to your desired title.

3. Controller.java connects the GUI to the functional parts of the code.

  • Notice how the three colors defined as constants are the three colors that appear in the game. Change all threeto your choice of colors.
  • Notice also how there are multiple errors on this class. These are due to the missing code in class Puzzle. These errors should get resolved as you complete each method needed in class Puzzle.

4. PuzzlePool.java maintains a collection of puzzles available from the Data subfolder.

  • Look over the file to become familiar with the code. No edits are needed.

5. Puzzle.java maintains a single Nonogram puzzle.

  • Instance data for this Puzzle are given. Two constructors and the toString methods are provided.
  • Complete all necessary methods by checking the API provided.

Main.java

public class Main extends Application {

@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("MyVersion");
primaryStage.setScene(new Scene(root));
primaryStage.show();
}


public static void main(String[] args) {
launch(args);
}
}

PuzzlePool.java

public class PuzzlePool {
private File[] files; //Array of files available in the Data subfolder
private ArrayList results; //List of puzzle names that correspond to the Puzzle objects

/**
* Loads all the text files from the Data subfolder,
* and stores each file into the files array.
* Also stores all filenames (before .txt) as the puzzle's title/name.
*/
public void loadFiles() {
results = new ArrayList<>();
String path = Paths.get(".\Data").toString();
files = new File(path).listFiles();
//System.out.println(path);

for (File file : files) {
if (file.isFile()) {
results.add(file.getName());
}
}
}

/**
* Selects a random puzzle from the collection of Puzzle objects available in array.
* @return the randomly selected puzzle
*/
public Puzzle getRandomPuzzle() {
int r = (new Random()).nextInt(results.size()); //new Random() here is an anonymous object
System.out.println("r=" + r); //used for debugging to know which is being chosen
return new Puzzle(files[r], 5); //game currently handles 5x5 puzzles only
}
}
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.