Homework 5

Skills: inheritance, hierarchies, class-design, methods, graphical classes, isa, hasa, composition.

Classes: Color, String, ArrayList, Graphics

Due Week 8: Saturday by 8pm.

In this assignment, you will design and code a basic "positional, graphical" class hierarchy of shapes and then use them to draw graphical objects.

Make sure you design and code using the class-design techniques and principles we have already covered!

Note: Phase 1 Due Date

Phase 1 (Steps 1-8) is due no later than the first Saturday during the week it is assigned. You should aim to be finished by the end of that week's Friday lab.
  1. Use PositionalGraphic as the base class for this hierarchy of graphical objects.

    PositionalGraphic will extend Canvas.

    Your design must be based on the idea of having a "bounding rectangle" for your shapes.

    What else does a positional graphic have?

    Please work in pairs on this design; you must work with a different partner than HW4.

    You must have your design reviewed by a TA no later than Thursday during TA office hours.

    You will override the parent's paint() method; your TA will explain what paint() should do during your design review.

    Once your group has had your design approved, you will work individually to complete the coding for this homework. Make sure to list partner names in the comment as designers for the class.

  2. Create and turn in TestPositionalGraphic to test your PositionalGraphic class. Start with this code: TestPositionalGraphic.java. All of your Test programs should follow this basic template.

  3. Design and code additional shape classes that extend your PositionalGraphic base class.

    Phase 1 classes are as follows:

    1. PositionalGraphic and its corresponding Test program.
    2. RectanglePG and its corresponding Test program.
    3. Either OvalPG or DiamondPG and its corresponding Test program.

    We will discuss this more during lecture. The requirements are:

    1. Your class hierarchy must have the following basic shapes, all based on PositionalGraphic:

      • OvalPG class
      • HalfCirclePG
      • RectanglePG
      • DiamondPG
      • TrianglePG (Isosceles triangle) Use an enum for the different triangle types:

        Isosceles Triangle

  4. For each basic shape, write the corresponding test application (TestHalfCirclePG, TestOvalPG, ...)

  5. You must also have 3 complex classes that consists of multiple shapes and demonstrates both inheritance and composition ("isa" PositionalGraphic and "hasa" PositionalGraphic(s)).

    The complex shapes you must code are:

    • HatPG class - a HatPG has a crown and a brim. The crown is a HalfCircle (or a Triangle) and the brim is a horizontal line defined by a RectanglePG.

    • IceCreamConePG class - an IceCreamConePG has a cone and a list of scoops. The cone is a Triangle with the point facing down. Each scoop in the list is an Oval and has its own color.

    • HeartPG class - a HeartPG has a Diamond and two Ovals, or a Triangle with two Ovals.

      If you have other ideas let me know and we can add them to the list of possiblities.

    Note that for each complex shape, the entire shape must fit within its bounding rectangle.

  6. For your complex shapes, write the corresponding test application (TestHatPG, TestIceCreamConePG, TestHeartPG, ...)

  7. Note: this assignment has 9 Test programs that you are required to code and turn in:

    1. TestPositionalGraphic

    2. TestOvalPG
    3. TestHalfCirclePG
    4. TestRectanglePG
    5. TestDiamondPG
    6. TestTrianglePG

    7. TestHatPG
    8. TestIceCreamConePG
    9. TestHeartPG

  8. Please download the ColorConverter.java code and add it to your project. Feel free to look at the pattern and see if you can add additional colors. You will use this code to prompt a user for a color - see if you can figure out how to use it.

Next week I will post more details on the final application for you to turn in in order to complete the assignment.

Finishing HW5