import java.util.Scanner; import java.util.Random; public class MyArray { public static final int SIZE = 4; private int [][] grid; public MyArray() { grid = new int[SIZE][SIZE]; for (int r = 0; r < SIZE; r++) { for (int c = 0; c < SIZE; c++) { grid[r][c] = 0; } } } public void display() { // Calling isNotNull if (isNotNull() == true) { for (int r = 0; r < SIZE; r++) { for (int c = 0; c < SIZE; c++) { System.out.print(grid[r][c]); } System.out.println(); } } else System.out.println("Can't display non-existant array"); } // returns true if grid reference is not equal to null // array doesn't exist, false otherwise // isNotNull // returns true if the row,column outside of the array bounds // false otherwise outBounds() public void start() { final int MAX = 9; Scanner in = null; Random aGenerator = null; int row = -1; int column = -1; display(); in = new Scanner(System.in); aGenerator = new Random(); System.out.print("Enter row to edit: "); row = in.nextInt(); System.out.print("Enter column to edit: "); column = in.nextInt(); // Calling isNotNull if (isNotNull() == true) { // Calling outBounds if (outBounds(row,column) == true) System.out.println("Cannot edit outside of grid"); else grid[row][column] = aGenerator.nextInt(MAX)+1; } else System.out.println("Can't edit non-existant array"); display(); } }