Program 19 60 points -GROUP PROJECT AVAILABLE Due May 1st 11:59 PM INTRODUCTION
ID: 3827616 • Letter: P
Question
Program 19 60 points -GROUP PROJECT AVAILABLE Due May 1st 11:59 PM INTRODUCTION From h wikipedia.org/wiki/Sudoku: "Sudoku (Japanese: sudoku), sometimes spelled Su Doku, is a logic-based placement puzzle, also known as Number Place in the United States. The aim of the canonical puzzle is to enter a numerical digit from 1 through 9 in each cell of a 9x9 grid made up of 3x3 subgrids (called "regions"), starting with various digits given in some cells (the "givens"). Each row, column, and region must contain only one instance of each numeral. For this assignment, you are going to write a Sudoku validator for 4x4 grids made up of 2x2 regions instead of 9x9 grids made up of 3x3 regions. Sudoku puzzles that use 4x4 grids only use the numerical digits 1 through 4 instead of 1 through 9 Here are two c 4x4 Sudoku grids: 4x4 Sudoku Example #1 4x4 Sudoku Example #2 Notice how each row, column and region has the individual numbers from 1 through 4 used only once. This means that the values used in each row. column and region must add up to 10 (1 2 3 4). This is how we will check our 4x4 Sudoku grids for this assignment. Allow your user to enter their Sudoku grids row-by-row, separating each of the four values by a space and hitting ENTER at the end of the row When the user has entered all 16 values into the program, you should output validation checks for each region, row and column. An example run can be seen below with sample user input underlined. Welcome to the Sudoku Checker v1.0! This program checks simple small 4x4 Sudoku grids for correctness. Each column, row and 2x2 region contains the numbers 1 through 4 only once To check your Sudoku, enter your board one row at a time, with each digit separated by a Hit ENTER at the end of a row space Enter Row 1. 3 2 4 1 Enter Row 2 4 1 3 2 Enter Row 3 1 4 2 3 Enter Row 4 2 3 1 4Explanation / Answer
import java.awt.*; // Uses AWT's Layout Managers import java.awt.event.*; // Uses AWT's Event Handlers import javax.swing.*; // Uses Swing's Container/Components /** * The Sudoku game. * To solve the number puzzle, each row, each column, and each of the * nine 3×3 sub-grids shall contain all of the digits from 1 to 9 */ public class Sudoku extends JFrame { // Name-constants for the game properties public static final int GRID_SIZE = 9; // Size of the board public static final int SUBGRID_SIZE = 3; // Size of the sub-grid // Name-constants for UI control (sizes, colors and fonts) public static final int CELL_SIZE = 60; // Cell width/height in pixels public static final int CANVAS_WIDTH = CELL_SIZE * GRID_SIZE; public static final int CANVAS_HEIGHT = CELL_SIZE * GRID_SIZE; // Board width/height in pixels public static final Color OPEN_CELL_BGCOLOR = Color.YELLOW; public static final Color OPEN_CELL_TEXT_YES = new Color(0, 255, 0); // RGB public static final Color OPEN_CELL_TEXT_NO = Color.RED; public static final Color CLOSED_CELL_BGCOLOR = new Color(240, 240, 240); // RGB public static final Color CLOSED_CELL_TEXT = Color.BLACK; public static final Font FONT_NUMBERS = new Font("Monospaced", Font.BOLD, 20); // The game board composes of 9x9 JTextFields, // each containing String "1" to "9", or empty String private JTextField[][] tfCells = new JTextField[GRID_SIZE][GRID_SIZE]; // Puzzle to be solved and the mask (which can be used to control the // difficulty level). // Hardcoded here. Extra credit for automatic puzzle generation // with various difficulty levels. private int[][] puzzle = {{5, 3, 4, 6, 7, 8, 9, 1, 2}, {6, 7, 2, 1, 9, 5, 3, 4, 8}, {1, 9, 8, 3, 4, 2, 5, 6, 7}, {8, 5, 9, 7, 6, 1, 4, 2, 3}, {4, 2, 6, 8, 5, 3, 7, 9, 1}, {7, 1, 3, 9, 2, 4, 8, 5, 6}, {9, 6, 1, 5, 3, 7, 2, 8, 4}, {2, 8, 7, 4, 1, 9, 6, 3, 5}, {3, 4, 5, 2, 8, 6, 1, 7, 9}}; // For testing, open only 2 cells. private boolean[][] masks = {{false, false, false, false, false, true, false, false, false}, {false, false, false, false, false, false, false, false, true}, {false, false, false, false, false, false, false, false, false}, {false, false, false, false, false, false, false, false, false}, {false, false, false, false, false, false, false, false, false}, {false, false, false, false, false, false, false, false, false}, {false, false, false, false, false, false, false, false, false}, {false, false, false, false, false, false, false, false, false}, {false, false, false, false, false, false, false, false, false}}; /** * Constructor to setup the game and the UI Components */ public Sudoku() { Container cp = getContentPane(); cp.setLayout(new GridLayout(GRID_SIZE, GRID_SIZE)); // 9x9 GridLayout // Allocate a common listener as the ActionEvent listener for all the // JTextFields // ... [TODO 3] (Later) .... // Construct 9x9 JTextFields and add to the content-pane for (int row = 0; rowRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.