Computer Science 252
Problem Solving with Java
Spring 2014, The College of Saint Rose
Lecture 23: Two-Dimensional Arrays
Date: Tuesday, April 22, 2014
Agenda
- Announcements
- Lecture 22 assignment recap
- In-class group exercise: we will work together to write a
program that reads in a series of daily sales reports for a
business, starting with a Sunday. The program will keep track of
and display in graphical form, the maximum sales amount and overall
average for each day of the week. The graphs should be updated
after each day's sales are entered. We will assume a valid range of
sales of 0-300 units per day.
- Two-dimensional arrays
Lecture 23 Assignment
Due at the start of class, Thursday, April 24.
Please submit answers to these questions
in Submission
Box under "LA23" 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)
Examples