Computer Science 523
Advanced Programming
Summer 2014, The College of Saint Rose
Lab 5A: Arrays and Java Swing
Due: 4:30 PM, Tuesday, June 24, 2014
This is the first of two new labs to come out this week. In this one,
you will get some practice with arrays and Java Swing components,
which will help you to prepare for the larger lab assignment that will
be due the following week.
You may work alone or with a partner on this lab. Only one submission
per group is needed.
Getting Set Up
To get your BlueJ environment set up for this week's lab assignment,
start BlueJ and choose "New Project" from the "Project" menu.
Navigate to your folder for this course and choose the name
"Lab5A" (no spaces) for the project.
Create a document where you will record
your answers to the lecture assignment and lab questions. If you
use plain text, call it "lab5A.txt". If it's a Word
document, you can call it whatever you'd like, but when you submit,
be sure you convert it to a PDF document "lab5A.pdf"
before you submit it.
Lecture Assignment Questions
We will usually discuss these questions at the start of class on the
lab due date, so no credit can be earned for late submissions of
lecture assignment questions.
LA Question 1: Write a method that takes an array of double values
as its parameter and returns the sum of all elements in the array.
(3 points)
LA Question 2: Write a method that takes an array of String values
as its parameter and returns an array of int that contains the
lengths of those Strings. That is, each element in the
returned array contains the length of the String in the
corresponding element of the parameter array. (4 points)
LA Question 3: Gaddis Algorithm Workbench exercise 5, p 532. (3
points)
LA Question 4: 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. (2 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. (4 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. (4 points)
Practice Programs
Practice Program: 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 (4 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 (4 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.
(7 points)
- Appropriate tests in main (5 points)
Practice Program: Gaddis Programming Challenge 1, p. 448. Write
this as a JApplet rather than a GUI application. (5 points)
Submitting
Before 4:30 PM, Tuesday, June 24, 2014, submit your lab
for grading. There are two things you need to do to complete the
submission: (i) Copy your file with the answers to the lecture
assignment and lab questions into your project directory. Be sure
to use the correct file name. If you prepared your answers in Word,
export to a PDF file and submit that. (ii) Upload a copy of your lab (a
.7z or .zip file containing your project directory) using
Submission
Box under assignment "Lab5A".
Grading
This assignment is worth 45 points, which are distributed as follows:
>
Feature | Value | Score |
Lecture Assignment Quetions | 20 | |
Matrix2D max method | 4 | |
Matrix2D scale method | 4 | |
Matrix2D multiply method | 7 | |
Matrix2D main method enhancements | 5 | |
Programming Challenge 1 | 5 | |
Total | 45 | |
|