Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*JAVA* I was wondering if I can get some help implementing this image into code. Thank you so much in advance! Write the Polygon interface

*JAVA*

I was wondering if I can get some help implementing this image into code. Thank you so much 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.

image text in transcribed

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 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Marketing Database Analytics

Authors: Andrew D. Banasiewicz

1st Edition

0415657881, 978-0415657884

More Books

Students also viewed these Databases questions

Question

=+ What are the information and consultation requirements?

Answered: 1 week ago

Question

=+ Should the MNE belong (why, why not)?

Answered: 1 week ago