Question: (JAVA) I have been assigned to implement from this image and I would like to get some hints and some help how to implement this

(JAVA)

I have been assigned to implement from this image and I would like to get some hints and some help how to implement this UML diagram. I thank you for the help in advance.

Write the Polygon interface and two classes (Triangle and Rectangle).

You can reuse Point in Java API or define your own.

Implement getPoints() and getArea() in the two subclasses.

Use Herons formula to compute a triangles area.

The area of a triangle = Sqrt(s(s-a)(s-b)(s-c))

where s = (a + b + c) / 2

a, b and c are the lengths of the triangles sides.

Write test code (in main() or with JUnit) that

Makes two different triangles and two different rectangles,

Contains those 4 polygons in a collection (e.g. ArrayList),

Use generics and an iterator

Prints out each polygons area.

Take advantage of polymorphism.

(JAVA) I have been assigned to implement from this image and I

Polygon > AreaCalculator - points: ArrayList areaCaloc 0..1 + Polygon( points: ArrayList, areaCalc: AreaCalce ator) + getArea(points: ...): float + setAreaCalc( calc: AreaCalculator); + addPoint( point: Point); + getArea): float TriangleAreaCalc return is.points points; RectangleAreaCalc areaCalc.getArea(points); this.areaCalc=areaCalc; Userlclient of Polygon: ArrayListPoint al = new ArrayList(); al.add( new Point(...) ); al.add( new Point(...) ); al.add( new Point(...) ); Polygon pnew Polygon( al, new TriangleAreaCalc)); p.getArea); // triangle's area p.addPoint( new Point(...) ); p.setAreaCalc(new RectangleAreaCalc); p.getArea); // rectangle's area

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!