Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA Sudoku problem In a Sudoku game, we have to re-build a grid with 9 rows and 9 columns. Each row and each column must

JAVA Sudoku problem

In a Sudoku game, we have to re-build a grid with 9 rows and 9 columns.

Each row and each column must contain all integers from 1 to 9.

You need to program a code that allows you to load Sudoku grids from files, manipulate the grids (placements, checks), and finally reproduce the grids again either on screen or in files. Sudoku files contain a sequence of space-separated number triplets, where each triplet corresponds to: x: line number. y: column number. z: value

In programming , columns and rows are most often numbered starting with zero.

Examples: Content of file part1.txt 001 012 023 034 045 056 067 067 078 089 102 113 124 135 146 157 168 179 181 203 214 225 236 247 258 269 271 282 304 315 326 337 348 359 361 372 383 405 416 427 438 449 451 451 473 484 552 563 574 585 607 618 629 631 642 653 664 675 686 708 719 721 732 743 754 765 776 787 809 811 822 833 844 855 866 877 888

Contents of the file part2.txt 016 112 214 319 417 511 618 713 815 027 129 221 328 425 523 626 722 824 033 138 235 332 436 534 631 737 839 048 141 243 347 449 545 644 746 842 059 157 252 355 568 667 769 861 074 173 279 376 471 577 672 775 878 081 186 288 385 483 582 689 784 887 092 195 297 394 498 599 693 791 89

Contents of the part3.txt file 014 116 218 313 411 517 615 712 819 022 127 225 324 428 529 623 726 821 031 133 239 335 436 532 637 734 838 045 148 246 349 447 541 642 743 844 057 159 256 568 669 767 866 079 174 273 371 472 576 678 775 877 086 182 287 388 489 585 684 781 883 098 195 291 397 493 594 696 799 892 In these examples, the data is not necessarily correct. It's your job to create a program that can handle errors.

Required Features/Classes

Your program must do three specific things: Load a file containing data according to the specified format (a sequence of digit triplets separated by spaces). You can choose the approach you prefer. The file can be retrieved online, by opening a file on your disk, or by standard input (stdin).

Your code should handle read errors. Validate that the file corresponds to a valid Sudoku table. That is, it must correspond to a 99 table where each number from 1 to 9 appears only once per column and only once per row.

For the purposes of this work, we do not require that each 33 subgrid contain all the digits from 1 to 9 (you can do this additional check if you wish, however).

If there is an error, your program should throw an exception. Your program should then apply a transposition to the array corresponding to a transposed matrix calculation and display the result on the screen.

Instead of displaying it on the screen, you (as the programmer) can save it as a new file or use another means of transmission. Choose the approach that most appeals to you as a programmer. You should test your solution with more than one grid; in particular, include a grid that is asymmetrical (not identical to its transpose) in your tests.

Give the result of at least two different tests, beyond the part1.txt file. You can use screenshots to present your results. You must explain your program carefully and in detail.

Each function and each variable of the program must be justified. The qualifiers (static, public, protected and private) must be justified one by one: you cannot use the keyword "static" without justifying it. If you submit your code without clear explanations and without justifying everything, a score of zero may be assigned, with no possibility of recovery. If your solution code is not valid Java, if it does not compile, a score of zero may be assigned. To pass this course, you must be able to write functional and correct Java code.

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_2

Step: 3

blur-text-image_3

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

Introduction to Algorithms

Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest

3rd edition

978-0262033848

Students also viewed these Programming questions