Computer Science 252

Problem Solving with Java

Fall 2014, The College of Saint Rose

Agenda

- Announcements
- Lab 8: Final Project implementation phase continues
- First look ahead to final exam
- review time: Tuesday, December 9, 9:00 PM
- exam: Thursday, December 11, 10:45-1:15
- more details next week

- Lecture 22 assignment recap, continued
- An additional two-dimensional array example
- Matrices
**In-class Exercise 24**- (20 lecture assignment points) due before the start of our next class.Your task is to add some functionality to the Matrix2D example and write code to test it in the

`main`method there. The functionality you are to add:- A method
`max`that returns the largest number in the matrix (5 points) - A destructive method, that is, a method that modifies the
matrix on which it is called, named
`scale`that multiplies each entry in the matrix by a number (5 points) - A non-destructive method, that is, one that does not change
the matrix on which it is called, named
`multiply`that works much like`add`but computes the matrix-matrix multiplication result. If you don't remember how to multiply matrices, see the "Matrix Product" section of the Wikipedia entry to Matrix multiplication. (10 points)

Please submit only the file

`Matrix2D.java`in Submission Box under "InClass24" before you leave class.- A method

Due at the start of class, Tuesday, December 2.

Please submit answers to these questions in Submission Box under "LA24" or in hard copy by the start of our next class. We will discuss these questions at the start of class, so no late submissions are accepted. Please be sure that your name is clearly indicated in all submissions.

The popular Sudoku puzzle game consists of a board that has 9 rows and 9 columns of numbers ranging from 1-9. Suppose we are writing a class to store a Sudoku board. We will assume that filled-in entries contain a number 1 through 9, and blank entries are represented by 0.

- Write a declaration of the instance variable
`board`that would store the board using a two-dimensional array of`int`. Show also the construction of the array. (3 points) - Write a method
`checkRowValidity`that takes a row number (let's use rows numbered 0-8 for simplicity) and checks that no two filled-in entries contain the same number within that row (this would be illegal in the game). It should return`true`if the row is legal,`false`if not. (6 points) - Assume you have a similar method
`checkColValidity`(no need to write it). Using your`checkRowValidity`and`checkColValidity`methods as building blocks, write a method`checkRowsColsValidity`that checks that all rows and columns are valid in the current board. (6 points)

Also, please complete these problems from the text:

- BDM Exercise 14.9.3, p. 399-401. (4 points)
- BDM Exercise 14.10.1, p. 402-403. (6 points)

Examples