CSSE 221: Fundamentals of Software Development Honors
JavaEyes
Work on this exercise by yourself,
but be quick to ask questions of your instructor, student assistants and classmates as desired.
Goals
The goals of this exercise are to:
- Continue to familiarize you with our development environment (Eclipse).
- Ensure that you can read and modify Java code.
- Introduce you to UML class diagrams.
- Make sure that you are clear on very basic OOP structural elements.
- Introduce you to checking out and turning in projects that are already under version control.
The Exercise - Overview
You will:
- Check out a simple GUI program named JavaEyes from a repository, by using Subclipse.
- Read the program and answer some questions about it.
- Make some easy modifications to the program.
- Commit your modified version back to the repository by using Subclipse.
Instructions, Part 1 - Checkout the Project
- Open Eclipse.
- Add the SVN Repository Exploring perspective.
- Here's how: Choose Window ~ Show View ~ Other...,
then choose SVN ~ SVN Repositories.
- You'll get an SVN Repositories view where your console lives.
You should see your individual repository (if not, go back and do the
HelloWorld assignment).
Expand it and you should see a JavaEyes folder.
- You should also see the HelloWorld folder
that you put into the repository yourself previously.
- Your instructor put this initial version of JavaEyes
into your individual repository.
- If you don't see your individual repository and JavaEyes,
get help now.
- Checkout your JavaEyes project.
- Here's how: Right-click on JavaEyes and select
Checkout....
Accept all defaults as you go through the Checkout dialogs.
- If Eclipse asks if you want to go to the Team Synchronizing perspective,
reply No.
- Get ready to read/modify the code.
Consider:
Checking out JavaEyes changed your Package Explorer view.
(It may also have changed your Problems view,
since JavaEyes intentionally has some errors.)
How is your Package Explorer view different
than it was before you checked out the JavaEyes project?
Instructions, Part 2 - Fix the compile-time errors
- Examine the Problems tab.
You should see two errors and four warnings.
- Fix the errors (but leave the warnings for now) by:
- Double-click on an error in the Problems tab
to go to the line where the error occurs.
- Note that the error is highlighted.
- Hover over the red circle-X
on the left margin, next to the line number.
- Click the red circle-X
to bring up the Quick Fix drop-down menu.
- Select and then apply an appropriate Quick Fix.
Note how Eclipse previews the effect of the selected Quick Fix
before you apply it.
Before continuing, make sure that you understand how to use Quick Fix.
Ask questions as needed.
- Run the program (the green arrow is handy)
and play around with some of its features.
Instructions, Part 3 - Read the code
- Answer the following questions as you browse the code.
- Note and use both the Package Explorer window
on the left-hand-side of Eclipse
and the Outline window on the right-hand-side of Eclipse.
Consider:
How many classes are in the JavaEyes project?
Consider:
How many constructors does the Eye class have?
Consider:
How many other methods does the Eye class in JavaEyes have?
Consider:
How many fields does the Eye class have?
- Hover over a variable anywhere in the code.
Note the help that pops up.
- Hover over a reference to a class anywhere in the code.
Note the help that pops up.
- Hover over a reference to a method anywhere in the code.
Note the help that pops up.
Instructions, Part 4 - Code-completion and compile-on-the-fly
- Find the code that declares the eye (not eyeball) color.
Change it to another (non-white) color of your choice.
- Do so by backspacing over white and noting the options available.
- Eclipse compiles on-the-fly.
This means it can find compile-time errors automatically for you and suggest fixes.
Consider:
In Eclipse, do you need a separate “build” or “compile” step
before you run?
Instructions, Part 5 - Fix a run-time error
- Run JavaEyes until you see a red run-time
error message in the Console window.
- It takes a while, and you have to move the eyeballs around a lot.
Ask if you don't see red.
- Decipher the red run-time
error message in the Console window. Ask questions as needed.
Consider:
What Exception (error) occurred, according to the error message?
Consider:
At what statement did the Exception (error) occur, according to the error message?
- Fix the source of the run-time error
(while keeping the rest of the program intact).
Instructions, Part 6 - Fix documentation errors
- The Problems tab shows four warnings,
all resulting from missing Javadoc comments.
Use Quick Fix on each warning to add a Javadoc comment.
Then fill in each Javadoc comment appropriately,
using the Javadoc comments elsewhere in the code as examples.
- Make sure that the warning messages go away before continuing.
- Make sure that your comments are accurate and appropriate.
- Note that the doc folder in Package Explorer is empty.
Generate the html Javadoc now by:
- Select Project ~ Generate Javadoc....
- In the Javadoc Generation dialog that appears:
- Confirm that the Javadoc command
is C:\Program Files\Java\jdk1.6.0_20\bin\javadoc.exe.
(If not, press Configure and browse to find it.)
- Check the JavaEyes checkbox if it is not already selected.
- Select the Protected radio button.
- Select the Use standard doclet radio button
and make sure the Destination
is the doc subfolder of your JavaEyes folder.
(If not, browse to find it.)
- Press Next to continue.
- In the Configure Javadoc arguments for standard doclet dialog that appears,
check the rt.jar checkbox. (You may have to scroll.)
- Press Finish
- If you get a message asking Do you want to update the Javadoc location...,
respond Yes.
- Note that the doc folder in Package Explorer now has lots of files.
Click on some of them to examine the generated Javadoc.
Pretty cool, yes?
- Try right-clicking on the html file for one of the JavaEyes' classes
and select Open with ~ Web browser.
In the browser that opens,
browse the JavaEyes classes and some of the non-JavaEyes classes that are linked.
- Confirm that the external browser shows the comments that you typed.
Confirm that those comments are accurate and appropriate -- if not,
fix the comments and regenerate the Javadoc.
Instructions, Part 7 - Add eyes (the has-a relationship)
- Check out the
UML class diagram for JavaEyes.
Consider:
Suppose that you want to add a 3rd eye that behaves just like the other two eyes.
What change(s) to the design are necessary?
That is, what change(s) must you make to the UML class diagram
to reflect the addition of a 3rd eye?
- Implement the design change(s) per the previous item -- that is,
add a 3rd eye that is just like the other two eyes.
- Add a 4th eye that is just like the other two eyes,
except that the 4th eye's color is green
and the 4th eyes' eyeball has color orange.
- Hint: this is almost as easy as adding the 3rd eye.
This part of JavaEyes showed you that you can implement different kinds of Eyes
by using fields -- in this case, fields for the Eye's color
and the color of the Eye's Eyeball.
You construct different kinds of Eyes by using the two-parameter constructor
that lets you specify these colors when the Eye is constructed.
Consider: Suppose that you want to implement square
Eyes (i.e., Eyes that are drawn as squares instead of as ovals). How could
you do this? (Just this about this; you do not need to implement this,
although it is not hard to do so.)
Instructions, Part 9 - Many eyes (using a loop)
- Using a loop,
add 99 Eyes (all of which behave the same way).
Far out!
- Hint: you don't need an array if you are careful.
- Finally, examine the Tasks tab at the bottom of Eclipse
and complete any TODO items for this project.
- Do you see how you can put your own TODO comments
and have Eclipse keep track of your own remaining tasks?
Instructions, Part 10 - Turn in your work (i.e., commit your project)
- Commit your JavaEyes project to the repository from which you checked it out, by:
- Right-click on JavaEyes in Package Explorer.
- Select Team ~ Commit.
- In the Commit dialog that appears, make sure that all your JavaEyes files are checked.
- In the Commit dialog, type a meaningful (or at least fun) log comment.