Programming Project 1b
Due at the beginning of Lab 2
This programming project should be done individually. It is okay to get
help from
the TAs and/or the instructor if you get stuck,
but you should try to do it on your own first.
Tip: You should get into the habit of
making backup copies of your work.
For this project you will write a program that inserts
several simple objects into a grid.
Write your program in small stages, compiling and testing after each
stage.
- Stage 1: Understanding the program
- Download and unzip the SimpleGridObject project into your
folder for this class, as you did with other projects during Lab 1.
- In BlueJ, open the project. You will notice that it has a
README file and three classes. The one whose name ends in "App"
represents the application or program as a whole, and contains the
main
method. You will be editing this method.
There is also a SimpleGrid
class. This represents a
grid that can contain various objects in its cells. Finally, there
is a SimpleGridObjectGUI
class. An object of this
class is necessary to display the grid and its contents; otherwise
the grid would exist but would be invisible.
(GUI stands for graphical user interface.)
- Double-click on the application class and read the
main
method without running the program yet.
- Read the class documentation for the SimpleGrid class. (Follow this link
rather than looking at the documentation via BlueJ; this version of
the class documentation has been stripped of some unnecessary
complexity.) Compare the constructor detail information in the
class documentation with the code in
main
that creates and initializes a grid. What
size grid do you think will be created -- how many rows, and how
many columns? (Write these expected results down.)
- Read the class documentation for the SimpleGridObjectGUI class.
(Again, follow this link rather than looking at the
documentation via BlueJ.) Compare the constructor detail
information in the class documentation with the code in
main
that creates and initializes the graphical
user interface object. What does each parameter being passed to
the constructor mean, according to the class documentation?
- Read the class documentation for the PictureBlock class.
This class does not appear in the BlueJ class diagram window
because it comes from a library that your project knows
about (the Grid Package library), rather than being part
of the project itself.
Which of the two constructors described in the class
documentation is being used in the
main
method?
What does each parameter being passed to
the constructor mean, according to the class documentation?
- Returning to the class documentation for the SimpleGrid class,
compare the method detail for the
add
method to the
code that puts the picture blocks into the grid. What does each
parameter mean, according to the class documentation? Draw a
picture that represents what you expect to see: a grid with the
expected number of rows and columns, with an indication of the
number and types of objects you expect to see in the grid and
where you expect to see them. A picture can be another way of
documenting expected results.
- Run the program. (Read the README file if you don't remember
how to run the program.)
- Is the size of the grid what you expected it to be? (Do the
actual results match the expected results?
- Are the number and types of objects in the grid as you
expected? Are they in the locations you expected?
- Click somewhere in the graphical user interface window and
then move the mouse over a cell containing a picture. Let the
mouse pause there until some text pops up. What aspect of the
code you looked at explains what you see?
- Move the mouse and pause over other cells. What do you see?
How might that information be useful to you?
- Read the Help information about this program from the
Help menu. What aspect of the code you looked at explains what
you see?
- Close the Help window, and then quit the program using the
File menu.
- Before going on to the next stage, clear the BlueJ Terminal
Window by clicking somewhere in the window (to bring the mouse focus
to the window) and choosing Clear from the Options menu.
- Stage 2:
-
Edit the
main
method to create a grid with 6 rows and 5
columns.
- Change the student name and date that appear in the Help
window to be accurate.
- Change the description for one or both of the picture
blocks.
- Before you compile and test your program, write down all the
differences you expect to see. Include what you expect to see when
you move the mouse over the cell in the lower right-hand corner of
the grid. (These will be the expected
results for your test.)
- Compile and test your program. Check the program's behavior
(the actual results) against the expected results.
(Did you remember to check the Help menu? The mouse-over text for
your pictures and for the cell in the lower right-hand corner?)
If the program did not behave as you expected, be sure to write down
any errors or unexpected results. You
should correct these and retest your program as Stage 2b before
moving on to Stage 3.
- Before going on to the next stage, clear the BlueJ Terminal
Window by clicking somewhere in the window (to bring the mouse focus
to the window) and choosing Clear from the Options menu.
- Stage 3:
-
Edit the
main
method to move the cactus out of the
first row and to move the skier back to the
lower right-hand corner of the grid. Compile and test your program.
Do your actual results match your expected results? If not,
re-edit, re-compile, and re-test.
- Before going on to the next stage, clear the BlueJ Terminal
Window by clicking somewhere in the window (to bring the mouse focus
to the window) and choosing Clear from the Options menu.
- Stage 4:
- Read the class documentation for the TextCell class.
This class also comes from the Grid Package library.
Edit the
main
method to add a letter to one of the
cells in the grid. Use the simplest TextCell
constructor (the one that takes only a single parameter) to do this.
Be careful not to put your new text cell in a cell that already
contains another item. (See the method details in the class
documentation for the SimpleGrid class,
to read about the restrictions on adding an object to the
grid.)
- Compile and test your program.
Compare your expected results to your actual results. If they do
not match, re-edit, re-compile, and re-test.
- Before going on to the next stage, clear the BlueJ Terminal
Window by clicking somewhere in the window (to bring the mouse focus
to the window) and choosing Clear from the Options menu.
- Stage 5:
- Fill the first row of the row of the grid with the letters
"BINGO", with each letter in a different text cell. (You can keep
your original text cell, if it wasn't in the first row, or remove it.)
- Do your actual results match your expected results? If not,
re-edit, re-compile, and re-test.
As always, before going on to the next stage, clear the BlueJ
Terminal Window by clicking somewhere in the window (to bring
the mouse focus to the window) and choosing Clear from the
Options menu.
- Stage 6:
- Read the class documentation for the ColorBlock class.
This is a third class from the Grid Package library.
Add several color blocks of different colors to your grid.
Be careful not to put a new item in a cell that already
contains an item. Again, use the simplest constructor, the one that
takes only one parameter. The easiest way to pass a color to the
constructor is to use one of the pre-defined colors in the
standard Java
Color
class, such as
Color.RED
, Color.BLUE
, Color.GREEN
,
Color.BLACK
, or Color.WHITE
.
(Capitalization matters in Java names.)
To find a full list of colors, Google "Java Color class" and
click on the link for the class documentation (the link will
include ".../docs/api/java/awt/Color.html"
).
- Compile and test your program.
Compare your expected results to your actual results. If they do
not match, re-edit, re-compile, and re-test.
As always, before going on to the next stage, clear the BlueJ
Terminal Window by clicking somewhere in the window (to bring
the mouse focus to the window) and choosing Clear from the
Options menu.
- Stage 7:
- Add at least one more picture block to your grid. Look in the
images
folder under your BlueJ project folder to see
what picture files have been provided for you.
- Do your actual results match your expected results? If not,
re-edit, re-compile, and re-test.
As always, before going on to the next stage, clear the BlueJ
Terminal Window by clicking somewhere in the window (to bring
the mouse focus to the window) and choosing Clear from the
Options menu. (What happens if you do not do this? You could run
the program several times in a row without clearing the window to
find out.)
- Stage 8:
- Deliberately test what happens when you write code that puts a
new object into a grid cell that already contains an object.
Compile and run your program to see what happens. What appears in
the BlueJ Terminal Window?
- Edit your program to remove the deliberate bug. Compile and
re-run your program to be sure that you have fixed it again. Be
sure to clear the BlueJ Terminal Window first.
- Deliberately test what happens when you write code that puts a
single object into two different grid cells.
Compile and run your program to see what happens. What appears in
the BlueJ Terminal Window?
- Edit your program to remove the deliberate bug. Compile and
re-run your program to be sure that you have fixed it again. Be
sure to clear the BlueJ Terminal Window first.
- Update the class documentation at the top of the application
program class.
Providing proper documentation is an important step towards writing
well-structured and reusable programs.
- When you are done,
change the name of your project folder to
YourName_PP1b
, zip it,
and submit the complete project to
Kit as a single zip file.