Graphics and Inheritance

Objectives
  1. Create a useful inheritance hierarchy.

  2. Use the hierarchy to create a program that draws different graphics primitives.

  3. Gain further understanding of inheritance and polymorphism.

Getting Started
  1. Copy P2 and rename it P3. Here is a tutorial on how to do this in Eclipse.

  2. Download the following files into your resources folder:

Description

The second part of the assignment requires you to modify the inheritance hierarchy and some of the code in the DrawProgram class.

Note
this mostly consists of getting rid of code and attributes in the primitive classes, and moving them to one of the new classes that we are going to introduce.

The UML diagram below shows the changes you must make and the JavaDoc describes the end result.

UML

Here are the steps for completing the second part of the assignment:

  1. Make the Primitive class abstract,

  2. Add an abstract draw method to the Primitive class that takes UserInterface as a parameter.

  3. Move the color and isFilled attributes and setters to the Primitive class, and remove them from all the other classes. Your program should still work.

  4. Add a RoundPrimitive class that extends Primitive, with the appropriate attributes and a generic draw method for Circle and Oval.

  5. Add a PolygonPrimitive class that extends Primitive, with the appropriate attributes and a generic draw method for Square, Rectangle, and Triangle.

  6. Remove everything but the constructor from Oval, Circle, Square, Rectangle, and Triangle. You may have to change the constructors in each class to conform to the parent constructor.

  7. Add a Polygon primitive that implements a generic Polygon, only a constructor is needed.

  8. In the load method for the DrawProgram class add a case for Polygons

    • the format is for a polygon is: "POLYGON,color,filled,numberPoints,x0,y0,x1,y1,x2,y2,…​"

  9. Delete the code for the draw method in the DrawProgram class.

  10. Re-implement that draw method so that it iterates over the ArrayList of primitives and calls draw.

    • The resulting code should be a loop with one statement and no instanceOf calls.

    • Consider using a foreach loop.

The image below shows the output from the complexPrimitives.txt file:

ComplexOutput
Specifications

Your program must meet the following specifications:

  • The code must produce the correct upload file and assertion messages.

  • Work on your own, as always.

  • You must package all source files into P3.jar for submission.

  • Assignments should be implemented using Java 1.8.

  • Make sure your code runs on machines in the COMCS 120 lab.

  • Submit your program to the Checkin tab as you were shown in the recitation.

  • Read the syllabus for the late policy.

  • We will be checking programs for plagiarism, so please don’t copy from anyone else.

Grading Criteria
  • 100 points for perfect submission

  • 0 points for no submission, if the program does not compile, submitted class files, etc

  • Preliminary Tests:

    • testCompile: verifies that all classes exist and compile. (0 points)

    • testSimple: verifies the drawing of simplePrimitives.txt. (20 points)

    • testComplex: verifies the drawing of complexPrimitives.txt. (20 points)

    • testPrimitive: verifies that Primitive class has the correct attributes and methods. (15 points)

    • testRound: verifies that RoundPrimitive class has the correct attributes and methods. (10 points)

    • testPolygon: verifies that PolygonPrimitive class has the correct attributes and methods. (10 points)

    • testText: verifies that Text class has the correct attributes and methods. (5 points)

    • testOther: verifies that all other primitive classes have only the constructor. (10 points)

    • testInstanceOf: verifies that DrawProgram does not use the instanceOf operator. (10 points)

  • Final Tests are identical to the preliminary tests.


Important
Submit P3.jar to Checkin