DOC PREVIEW
UNC-Chapel Hill COMP 401 - COMP 401 Representation

This preview shows page 1-2-3-4-5-38-39-40-41-42-43-76-77-78-79-80 out of 80 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 80 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 80 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 80 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 80 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 80 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 80 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 80 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 80 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 80 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 80 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 80 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 80 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 80 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 80 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 80 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 80 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 80 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Slide 1More on ObjectsTest-First ApproachMathematical PointJava Coordinate SystemPoint InterfaceStubs for ACartesianPointACartesianPoint TesterPoint RepresentationsAlgorithmsClass: ACartesianPointClass: APolarPointUsing the Interface and Its ImplementationsRepresenting Geometric ObjectsUsing ObjectEditorJava GraphicsAdding Tree ViewTree ViewRemoving Graphics ViewTree-only ViewObjectEditor GraphicsObjectEditor Point RulesEquivalent RepresentationsReason for ErrorWhat is in a Representation?Typing Point ObjectsLine?Describing LinesLine InterfaceLine ImplementationAnotherLine InterfaceSlide 32Predefined, Primitive vs. Programmer-Defined, ObjectKinds of TypesProgrammer-defined vs. Predefined TypesStructured vs. Atomic PropertiesStructure vs. Atomic TypesDecomposing AnAnotherLine InstancePhysical StructureLogical StructureLogical Structure Shown by ObjectEditorPhysical Structure Shown by DebuggerTwo Ways to Decompose ObjectsDrawing the Physical Structure of a Value of Some TypeDrawing the Logical Structure of a Value of Some TypeInstance-Specific StructureInstance-Specific StructureAtomic vs. Structure TypesGraphics Types Sees So FarObjectEditor Shape RulesXY-based ObjectEditor Shape RulesPoint-based ObjectEditor Shape RulesObjectEditor Bounding Box RulesObjectEditor Shape RulesObjectEditor TextBox RulesObjectEditor Label RulesLabel ImplementationUsing ALabelCreating Other Geometric ObjectsACartesianPlaneACartesianPlaneACartesianPlane PropertiesACartesianPlane PropertiesACartesianPlane StubsACartesianPlane ImplementationACartesianPlane ImplementationACartesianPlane ImplementationRefactoring Label CodeRefactoring Label CodeACartesianPlaneShuttle LocationShuttle LocationShuttle LocationShuttleLocation PropertiesAShuttleLocation ImplementationAShuttleLocation ImplementationAlternate Views of Logical StructureLines of CompositionEXTRA SLIDESAScalableNesterCOMP 401REPRESENTATIONInstructor: Prasun Dewan2MORE ON OBJECTSTest-first approachStubsTwo-way dependenciesRepresentations with errorsStructure vs. atomic typesPhysical vs. logical structureGraphics types3TEST-FIRST APPROACHWrite the interfaceCreate a class with stubs for each interface method and constructorIf method is procedure method does nothingIf method is function, it returns 0 or null valueNo variables need be declared as this point!Write a tester for itWrite/rewrite in one or more stub methodsUse testerIf tester results not correct, go back to 4Steps may be combined for simple classes!4MATHEMATICAL POINTX.Y Rq.5JAVA COORDINATE SYSTEMYX(0,0)(3,2)pixelsX and Y coordinates must be int valuesRadius and Angle can be doubleAngle is a decimal value between 0 and 26POINT INTERFACEpublic interface Point {public int getX(); public int getY(); public double getAngle(); public double getRadius(); }Read-only properties defining immutable object!7STUBS FOR ACARTESIANPOINTpublic class ACartesianPoint implements Point {public ACartesianPoint(int theX, int theY) { }public int getX() {return 0;}public int getY() {return 0;} public double getAngle() {return 0;}public double getRadius() {return 0;}}8ACARTESIANPOINT TESTERpublic class ACartesianPointTester {public void test (int theX, int theY, double theCorrectRadius, double theCorrectAngle) {Point point= new ACartesianPoint (theX, theY);double computedRadius = point.getRadius();double computedAngle = point.getAngle();System.out.println("------------");System.out.println(“X:" + theX);System.out.println(“Y:" + theY);System.out.println("Expected Radius:" + theCorrectRadius);System.out.println("Computed Radius:" + computedRadius);System.out.println(“Radius Error:" + (theCorrectRadius - computedRadius));System.out.println("Expected Angle:" + theCorrectAngle);System.out.println("Computed Angle:" + computedAngle);System.out.println(“Angle Error:" + (theCorrectAngle - computedAngle));System.out.println("------------");}public void test () {test (10, 0, 10.0, 0); // 0 degree angletest (0, 10, 10.0, Math.PI / 2); // 90 degree angle}}9POINT REPRESENTATIONSX, Y (Cartesian Representation)Radius, Angle (Polar Representation)X, RadiusX, Y, Radius, Angle…Does not completely specify the point10ALGORITHMSX.Y Rq.Cartesian RepresentationR = sqrt (X2 * Y2) = arctan (Y/X)Polar RepresentationX = R*cos()Y = R*sin()11CLASS: ACARTESIANPOINTpublic class ACartesianPoint implements Point {int x, y;public ACartesianPoint(int theX, int theY) {x = theX;y = theY;}public int getX() {return x;}public int getY() {return y;} public double getAngle() {return Math.atan2(y, x);}public double getRadius() {return Math.sqrt(x*x + y*y);}}12CLASS: APOLARPOINTpublic class APolarPoint implements Point {double radius, angle;public APolarPoint(double theRadius, double theAngle) {radius = theRadius ;angle = theAngle;}public int getX() {return (int) (radius*Math.cos(angle));}public int getY() {return (int) (radius*Math.sin(angle));}public double getAngle() {return angle;} public double getRadius() {return radius;}}13USING THE INTERFACE AND ITS IMPLEMENTATIONSPoint point1 = new ACartesianPoint (50, 50); Point point2 = new APolarPoint (70.5, Math.pi()/4); point1 = point2;Constructor chooses implementationConstructor cannot be in interface14REPRESENTING GEOMETRIC OBJECTSGeometric example to show multiple useful implementations of an interfaceMost geometric objects have multiple representations15USING OBJECTEDITORObjectEditor.edit(new ACartesianPoint (25, 50));16JAVA GRAPHICSYX17ADDING TREE VIEW18TREE VIEW19REMOVING GRAPHICS VIEW20TREE-ONLY VIEW21OBJECTEDITOR GRAPHICSCan automatically display objects representing points, rectangles, ovals, and lines as corresponding graphicsJava provides libraries to manually display graphicsHas rules for recognizing these objectsRules based on Java graphics standardsInverted coordinate systemCartesian coordinates for pointsBounding rectangles for lines, rectangles, ovalsPlus naming conventions22OBJECTEDITOR POINT RULESAn object is recognized as a point representation if:Its interface or class has the string “Point” in its nameIt has readable int properties, x and y, representing Cartesian coordinatesCan have additional propertiespublic interface Point {public int getX(); public int getY(); public double getAngle(); public double getRadius(); }23ObjectEditor.edit(new APolarPoint (195.05, 0.87)); ObjectEditor.edit(new ACartesianPoint (125, 149)); EQUIVALENT


View Full Document

UNC-Chapel Hill COMP 401 - COMP 401 Representation

Documents in this Course
Objects

Objects

36 pages

Recursion

Recursion

45 pages

Load more
Download COMP 401 Representation
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view COMP 401 Representation and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view COMP 401 Representation 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?