|
Bill Teter email: william.teter@plattsburgh.edu |
|
|
Lab 3 For loops and classes In this lab you will be adding new features to the Sudoku project. Copy
all code from your lab1 into a new directory called lab3. You may use my
code if you like. It is in my public directory: Write a new class called Position. The class will have two int fields between 0 and 8 inclusive. Call the two fields row and column. A Position object then designates a position on the Sudoku board. There should be a constructor in the Position class with two int parameters. Write the two accessor methods called getRow() and getColumn() that return the row and column respectively of a Position object. Write a toString method that returns a String with the row and column ints between square brackets; eg [2,3]. Write a equals method with the signature: public boolean equals(Object o) which returns true if and only if o is an instance of a Position object and is equal to this position. Write a test program to test each of these methods. Add to Board class Add to the Board class a accessor method that returns the Character at a Position specified by a parameter: public Character getPosition (Position p) Write a mutator to add a character to the board at a specified position: public void setPosition(Position p, Character ch) Write a method that returns the number of non-null characters in the board: public int nonNullCount() Write methods that return the number of non-null characters in a given row, or column or cell. Remember a cell is a 3 by 3 sub-array of the board. A board has 9 cells. public int nonNullCountRow(int r) public int nonNullCountColumn(int c) public int nonNullCountCell(Position p) Write a method that checks that a given row, column or cell is valid. In each case valid means no character occurs more than once. public boolean validRow(int r) public boolean validColumn(int c) public boolean validCell(Position p) Finally write method called valid that checks that every row, column and cell on the board is valid. public boolean valid() |