Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise l: Consider the following shapes; Ellipse, Cirele, Triangle, Equilateraliriangle, Each shape should have a name, a method to compute its perimeter, and another method

image text in transcribed
Exercise l: Consider the following shapes; Ellipse, Cirele, Triangle, Equilateraliriangle, Each shape should have a name, a method to compute its perimeter, and another method to compute its area. The name should be an instanee variable of type String. Design your inheritance hicrarchy with the common features in the superclass Shape. Notice that the area and perimeter are common to all Shapes, but we don't know how to compute the area or perimeter for a general shape. The ellipse class has a major and minor axes a and b. respectively. The constructor should assign the larges value to a and smallest to b. The area and perimeters of an ellipse are: Perimeter =P=2(a++b2)(ab)2/2 [Note that if a=b=r, then P=2r ] Area=A=ab. The Triangle class has three instance variables sidel, side2, and side3. The formula for the area and perimeter of a general Triangle with sides A,B, and C is given by. AREA=S(SA)(SB)(SC) PERIESTER =A+B+C S=2A+B+C The condition for any three positive values to make sides of a Triangle is: sideltside2>side3 and side2 4 side 3> sidel and side3 + sidel>side2 You need to check this condition inside the constructor. If it is not satisfied, print an error message and terminate the program, otherwise make your Triangie object. The three sides of the cquilateral triangle are equal. Make a Test class where you make objects from the different classes and store them in an array. of type Shape. Then, make a loop and print the objects name, area, and perimeter through toString ie, you need to override toString in the Shape class only. Note: Use Math.sqre) to find the square root. The following example shows the usage of lang Math sqri0) method Inport java.lang."; public class Kathoeno t public static vold main(String[] ares) f Xf get two double nutbers nubers double x=9; double y=25 : If print the seuare root of these doubles

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

Database Application Development And Design

Authors: Michael V. Mannino

1st Edition

0072463678, 978-0072463675

More Books

Students also viewed these Databases questions

Question

Describe how a parcel delivery company might use standard costs?

Answered: 1 week ago

Question

Describe how to train managers to coach employees. page 404

Answered: 1 week ago

Question

Discuss the steps in the development planning process. page 381

Answered: 1 week ago