Recitation 5 September 23, 2011
As you come in... Please sit next to someone you will collaborate with for today’s recitation. Choose someone with whom you have NOT collaborated during a previous recitation.
Announcements Object Editor 18 available on course website Remove Object Editor jar file from all submissions Compress & crop images in Word files Capitalize class & package names correctly
Today’s Goals: Create a composite graphics object Display graphics in ObjectEditor Get some practice with test-first programming
Graphics A class can be interpreted as a basic graphics object if it follows a set of rules Naming conventions Interface conventions Can create composite graphics objects Class has a logical structure that contains properties of a line, circle, etc.
Object Editor Point Rules An object is recognized as a point representation if: Its interface or class has the string “Point” in its name It has integer properties, x and y, representing cartesian coordinates public interface Point { public int getX(); public int getY(); }
Object Editor Line Rules An object is recognized as a rectangle/line/oval if: Its interface or class has the string “Rectangle” / “Oval” / “Line” in its name It has properties describing the bounding box of the shape public interface Line { public Point getLocation(); public int getWidth(); public int getHeight(); }
Composite Graphical Objects Compose the existing geometric objects into a logically structured object Recall the cartesian plane example public interface CartesianPlane{ public Line getXAxis(); public Line getYAxis(); public Label getXLabel(); public Label getYLabel(); public int getAxesLength(); public void setAxesLength(int length); }
Recitation Specification Download Recitation5.zip from the Recitations page: Add the Object Editor jar to your Recitation5 project Create a CartesianTriangle class that implements Triangle A Triangle is a composite graphics object that consists of three Line objects that share endpoints The Triangle constructor takes six integers, in this order: x1, y1, x2, y2, x3, y3. The constructor uses these values to create three Line objects, line1 from (x1,y1) to (x2,y2), line2 from (x2,y2) to (x3,y3), and line3 from (x3,y3) to (x1,y1). NOTE: Order matters! Define getters for each of the Line objects: getLine1(), getLine2(), and getLine3()
Testing for correctness You can only edit the CartesianTriangle class – editing any other class is forbidden Recitation5.java contains tests for CartesianTriangle Your implementation is correct if you can run Recitation5 and get “All tests passed” and this: