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 5 and sections 6.1-6.2. As you read, see if you can answer the self-check questions. If there is something you do not understand, make a note of it so you can ask about it in class.
  2. Edit the Big Java Review Wiki on ANGEL, adding answers to 4 stars of the review exercises from chapter 5. Be sure to carefully follow the instructions for doing this that are posted on the Wiki. Note:  There are a lot of review questions in Chapter 5, so each of you should answer a total of 4-stars worth.
  3. Spend a few minutes experimenting with the kinds of things that we did in the Session 4 class.  Look up the documentation of some of the classes we used. In particular, look up in the Java API documentation some of the Shape classes and interfaces, such as Shape, Ellipse2D, Ellipse2D.Double, Line2D, Line2D.Double,  Polygon, Rectangle, Arc2D, Arc2D.Double.

  4. 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. (3 points) 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, which you should create in the  IntroToJavaGraphics project.  You can copy and paste a lot of the “boilerplate” code from the FirstGraphics project that we did in class.

      Complete a “work of art” using all of the 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 that 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. (9 points) Circle of Circles: Your work for this problem should be done in the classes CicrcleOfCircles and CirclesComponent. I suspect you’ll find this problem substantially more challenging than previous programs from this course.

      When the main() method of CicrcleOfCircles 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.
      • You’ll probably find a loop like this helpful:
        for (double angle = 0; angle < Math.PI * 2; angle += 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

We will grade your Wiki contributions using ANGEL. Turn-in your programming work by committing it to your SVN repository. Everything is due at 8:05 AM on the day of Session 05.