CSSE 220 – Object-Oriented Software Development

Homework 4

Objectives

Begin working with graphics in Java. More practice reading and applying the API documentation and writing Javadocs.

Tasks

  1. Complete the assigned reading for the next session: Chapter 3. As you read, see if you can answer the self-check questions. If there is something you do not understand, make note of it so you can ask about it.
  2. Complete the assessment exercise over this reading on ANGEL (under Lessons → Assignments).
  3. Programming:
    1. Your programming work for this assignment must be done in the IntroToJavaGraphics project inside Eclipse. Use the SVN Repository Exploring perspective to check out this project, then switch back to the Java perspective.

    2. Release your inner Van Gogh: But keep your ears, we hope.

      You should do your programming for this task in the MyViewer and MyComponent classes that we started together in class.

      Complete a “work of art” using shape classes that we used in class, plus at least one class from the java.awt.geom package that we didn’t use together. (There are some wild classes in that package. Arc2D.Double and RoundRectangle2D.Double are probably the most straightforward of the classes we didn’t cover yet.)

      You’ll probably find this task easier if you sketch your drawing on paper first. That way you won’t be trying to be artistic while also trying to master the Java classes.

    3. Circle of Circles: Your work for this problem should be done in the classes CircleOfCircles and CirclesComponent. I suspect you’ll find this problem substantially more challenging than the ones so far.

      When the main() method of CircleOfCircles is run the program should ask the user for three numbers (see hint below):

      1. Radius of a “big circle”,
      2. Number of individual circles to draw,
      3. Radius for all of the individual circles.

      Your program then draws a “Circle of Circles” pattern like the ones in the figures below. The centers of the individual circles are equally spaced around the “big circle”. The “big circle” isn't actually drawn. Note that the “big circle” may, in fact, have a smaller radius than the individual circles.

      Here are some tips to get you started:

      • We’ve already “wired” the two provided classes together so that the inputs you collect in the main() method of CircleOfCircles are available in the paintComponent() method of CircleComponent. But you still have to collect the inputs and assign them to the provided variables.
      • Here’s an example of getting user input using JOptionPane:
        String input = JOptionPane.showInputDialog("Enter the big radius:");
        double bigRadius = Double.parseDouble(input);
        
      • The trig functions are in the Math class of the java.lang package. For example, you can calculate the sine of π/2 like this: Math.sin(Math.PI/2.0). See the API Documentation for more details.
      • Recall that basic for loops in Java are almost exactly like C, except we can declare a variable in the loop initializer. For example:
        for (double d = 0.0; d < max; d += stepSize) {
            // do something here
        }
        

      Here are some example outputs:

      Example output of CircleOfCircles Example output of CircleOfCircles
      Example output of CircleOfCircles Example output of CircleOfCircles

Turn-in Instructions

Turn-in your programming work by committing it to your SVN repository.