Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write an inheritance hierarchy for the classes Quadrilateral (an abstract class), Trapezoid, Parallelogram, Rectangle, and Square; decide on an inheritance hierarchy and then code it

Write an inheritance hierarchy for the classes Quadrilateral (an abstract class), Trapezoid, Parallelogram, Rectangle, and Square; decide on an inheritance hierarchy and then code it up in Java. Create and (re)use a Point class that has double instance variables: x-coordinate and y-coordinate (each quadrilateral will have 4 Points, declared in the Quadrilateral class as protected). Each class must be defined in a separate .java file. Prompt the user for the 4 points; do NOT require that the user enter the points in any order, but DO require that 2 of the four points lie on the x-axis, and as all of the figures have least one pair of parallel sides, also require that at least one parallel side lie along the x-axis (this simplifies the following considerably). Determine the type of figure entered (trapezoid, parallelogram, rectangle, or square), and throw an exception if the quadrilateral is not one of the above figures; inform the user of the error and exit the program. If the points form a valid figure, then instantiate the appropriate figure. Inform the user of the type of figure, and then find and display its area. Recall the formulas for the area of these quadrilaterals:

Trapezoid area: the height times the sum of the two bases

(the bases are the parallel sides);

Parallelogram and rectangle area: the base times the height;

and, Square area: the square of one side.

For each class write at least one constructor, (get and set methods for each class are optional), and a method that computes the area of the object of each class (except for Point and Quadrilateral; in the Quadrilateral class declare this method as abstract). Write a separate driver to test all of your methods. Every class, including Point and Quadrilateral, MUST have a concrete toString() method using String.format()

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

Advances In Databases And Information Systems 23rd European Conference Adbis 2019 Bled Slovenia September 8 11 2019 Proceedings Lncs 11695

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Aida Kamisalic Latific

1st Edition

3030287297, 978-3030287290

More Books

Students also viewed these Databases questions