Computer Science 252
Problem Solving with Java
Spring 2016, The College of Saint Rose
Lecture 23: Two-Dimensional Arrays
Date: Thursday, April 21, 2016
Agenda
Lecture 23 Assignment
Due at the start of class, Tuesday, April 26.
Please submit answers to these questions
either as a hard copy (typeset or handwritten are OK) or by email to
terescoj AT strose.edu by the start of class. Please use a clear subject line
when submitting by email (e.g., CSC 252 Lecture
23 Assignment, Mary Smith). We will discuss these
questions at the start of class, so no late submissions are
accepted.
Note: this is a somewhat longer lecture assignment than usual.
First, some review since you'll have to do this again on the final.
- Write a method that takes an ArrayList of objects that
implement the Drawable2DInterface as its parameter (the
parameter will have type ArrayList<Drawable2DInterface>) and
returns the number of the objects in the array whose x-coordinates
are less than 200. (5 points)
- Write a method that takes an int and an ArrayList of
Integer as parameters and returns another ArrayList of
Integer that includes only those values from the original
ArrayList that are greater than the int parameter's
value. (5 points)
The popular Sudoku puzzle game (for example, see
here) 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)
Terminology
- two-dimensional arrays
- row major/column major order
Examples