Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with a Java program for solving the task with notes explaining what each part does. In this assignment, you are asked to

I need help with a Java program for solving the task with notes explaining what each part does.

image text in transcribedimage text in transcribedimage text in transcribed
In this assignment, you are asked to implement a Java program solving "tiling problem" using recursion. In this problem, you are given a square-shaped board of size n x n where n is a power of 2 (2, 4, 8, 16, 32, . . .). The board has a grid-like pattern and is made of n2 1 x 1 small squares called cells (see Figure 1). The goal is to cover this board with L-shape tiles in a way that only one cell remains uncovered. Given L shape tile that is to be used Missing 1 x 1 cell to fill the board with 1 missing cell in board Figure 1: An 8 x 8 board with a missing cell at coordinates (3,1). 1 Program Input Your program should receive three integers as command line arguments: 1. args[o]: The value of n (if it is not power of 2, the program should print out an appropriate error message and terminate) 2. args[1]: Index of the row where the missing cell is located. The valid values are 0, 1,.... n - 1 where 0 means the first (top) row and n - 1 means the last (bottom)(a) Step 1: covering the board center with one (b) Recursively dividing the top-left quarter tile and divide the board into four quarters. into four sub-problems. (c) Recursively dividing other quarters into four (d) Solving the smallest sub-problems by cover- sub-problems. ing the 2X2 sub-boards (base case of recursion). Figure 2: An example of how to solve the tiling problem recursively. row. If the index is not an integer or is out of range, the program should print out an appropriate error message and terminate. 3. args[2]: Index of the column where the missing cell is located. The valid values are 0, 1,....n - 1 where 0 means the first (left-most) column and n - 1 means the last (right-most) column. If the index is not an integer or is out of range, the program should print out an appropriate error message and terminate. 2 The Idea of Recursive Solution The recursive solution first covers three out of the four cells at the board center with one tile (Figure 2.a). The way this tile is placed depends on where the missing cell is: on the first quarter (top-left), second, third or fourth. Then, it divides the board into four quarters eachwith dimensions n/2 X n/2. Then, it solves each quarter recursively (Figures 2.b-2.d). 3 Output Format Using three characters '-', '+', and 'I', draw the final place- +--++--+ ment of tiles on the board. Use character "* to show the empty cell. For example, in order to show the placement of 1-+1 1-+1 tiles in Figure 2.d, the program must generate the string represented in Figure 3. This string must be written in the output file "out.txt". +-11-+11 1 *- +1 1-+ 4 Submissions +-1-+1-+ You need to submit a .zip file compressing the Java source file(s) of your program (.java files) and a readme.txt intro- 1 1+--+11 ducing every class in your program and all the methods and instance fields of each class. 1+-11-+1 +--++--+ Figure 3: Expected output showing the placements of tiles in Figure 2.d. 3

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

Identify and classify different market entry modes.

Answered: 1 week ago