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.

Consider: When you see “Consider” in red, where do you go to report your answer to that question?
Consider: When you see “Consider” in red, do you go to the Angel report to answer that question right at that time or only after you have done the rest of the exercise?
Consider: When you see “Consider” in red, at that point do you answer only the single question in that “Consider” or all the questions in the Angel report?

Goals

The goals of this exercise are to:

The Exercise - Overview

You will:

    Instructions, Part 1 - Checkout the Project

  1. Open Eclipse.
  2. Switch to the SVN Repository Exploring perspective.
  3. You'll get an SVN Repositories view where your Package Explorer usually lives. You should see your individual repository. Expand it and you should see a JavaEyes folder.
  4. Checkout your JavaEyes project.

  5. Return to the Java perspective to begin reading/modifying the code.
  6. 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?
    Consider: What perspective do you use for checking out a project from a repository?
    Consider: What perspective do you use for reading/modifying the code of a project?
    Consider: What menu do you use to change perspectives?

    Instructions, Part 2 - Fix the compile-time errors

  7. Examine the Problems tab. You should see two errors and four warnings.
  8. Fix the errors (but leave the warnings for now) by:

    Before continuing, make sure that you understand how to use Quick Fix. Ask questions as needed.

  9. Run the program (the green arrow is handy) and play around with some of its features.
  10. Instructions, Part 3 - Read the code

  11. Answer the following questions as you browse the code.
    Consider: How many classes are in the JavaEyes project?
    Consider: How many methods does the Eye class in JavaEyes have?
    Consider: How many constructors does the Eye class have?
    Consider: How many fields does the Eye class have?
  12. Before continuing, make sure that you understand how to use the Package Explorer and Outline windows. Ask questions as needed.

  13. Hover over a variable anywhere in the code. Note the help that pops up.
  14. Hover over a reference to a class anywhere in the code. Note the help that pops up.
  15. Hover over a reference to a method anywhere in the code. Note the help that pops up.
  16. Instructions, Part 4 - Code-completion and compile-on-the-fly

  17. Find the code that declares the default eye (not eyeball) color. Change it to another (non-white) color of your choice.

    Before continuing, make sure that you understand how to use Eclipse's code completion. Ask questions as needed.

  18. 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?
  19. Instructions, Part 5 - Fix a run-time error

  20. Run JavaEyes until you see a red run-time error message in the Console window.
  21. Decipher the red run-time error message in the Console window. (You'll need to scroll up.) 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?
  22. Fix the source of the run-time error (while keeping the rest of the program intact).
  23. Before continuing, make sure that you understand how, when an exception (run-time error) occurs, to find what exception occurred and at what statement it occurred. Ask questions as needed.

    Instructions, Part 6 - Fix documentation errors

  24. 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.
  25. Note that the doc folder in Package Explorer is empty. Generate the html Javadoc now by:
  26. Note that the doc folder in Package Explorer now has lots of files. Click on index.html to examine the generated Javadoc. Pretty cool, yes?
  27. Try right-clicking on index.html 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.

    Before continuing, make sure that you understand the structure of the information in a Javadoc-generated page for a class. Ask questions as needed.

  28. If you prefer the internal browser (i.e. inside Eclipse), right-click on index.html (inside Eclipse) again and select Open with ~ Internal Web Browser. Eclipse will remember whatever you did most recently, internal or external.
  29. Confirm that the browser shows the comments that you typed. Confirm that those comments are accurate and appropriate -- if not, fix the comments and regenerate the Javadoc.
  30. Instructions, Part 7 - Add eyes (the has-a relationship)

  31. Recall 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?
  32. Implement the design change(s) per the previous item -- that is, add a 3rd eye that is just like the other two eyes.
  33. 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.
  34. 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 use this differentiation-by-using-fields pattern to do so? (Just write your answer in the Angel Report; you do not need to implement this, although it is not hard to do so.)

    Instructions, Part 8 - Add eyes (the is-a relationship)

  35. Another way to implement different kinds of Eyes is to implement subclasses that extend Eye. This approach is better than the field-approach of the previous section whenever the new Eyes are different enough from the standard Eyes to deserve their own subclasses.

    Implement a new class called SquareEye that extends Eye and overrides the Eye's paintComponent method. A SquareEye should be (as the name suggests) drawn as a square instead of an oval. (Its eyeball remains round.)

    Construct and add at least one instance of a SquareEye to demonstrate that your SquareEye works correctly.

  36. Consider: When you extend a class, how do you make the subclass behave differently than the superclass?

  37. Extra credit, just for grins: If you wish (and ONLY if you wish), make the eyeball of a SquareEye alternate between two points as the mouse is moved, or continually roll around clockwise, or do something else cool.
  38. Instructions, Part 9 - Many eyes (using a loop)

  39. Using a loop, add 99 more Eyes (all of which behave the same way). Far out!
  40. Instructions, Part 10 - Turn in your work (i.e., commit your project)

  41. Examine the Tasks tab at the bottom of Eclipse and complete any TODO items for this project.
  42. In all your code throughout this term, type Control-Shift-F before you turn it in (and occasionally throughout your coding).
  43. Commit your JavaEyes project to the repository from which you checked it out, by: