Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please solve it in java. The GeometricObject, Circle and Rectangle classes are given for this exercise. You may need to make necessary changes to the

Please solve it in java.

image text in transcribed

image text in transcribed

The GeometricObject, Circle and Rectangle classes are given for this exercise. You may need to make necessary changes to the classes other than what is mentioned below. This exercise is about polymorphism. Declare the getPerimeter) and getArea) methods in the GeometricObject class. These two methods should be declared as abstract because they cannot be implemented in the Geometric Object class. However, they are implemented in the subclasses. Change the toString) method of Triangle in Part (i) to return a string of "Triangle Object". Implement toString) method in Circle and Rectangle class to return a string of "Circle Object" and "Rectangle Object" respectively Implement a static method called larger in your test program. This method takes two geometric objects of the same type as arguments and returns the object with larger area. If two objects have the same area, the method returns null. If two geometric objects are not of the same type are used as arguments, the function throws DifferentTypeException. DifferentTypeException is a user defined exception. Define it for your larger method. The function signature of larger is as follow: static GeometricObject larger(GeometricObject g1, GeometricObject g2) throws DifferentTypeException Write a test program called TestLarger to test if your larger method works properly. Create different types of geometric objects to call the larger method. You should test your method with 2 Circles, 2 Rectangles, 2 Triangles, and 2 different object types should throw DifferentTypeException. Print appropriate details about the object returned by larger method such as description, radius, width, height, sides, perimeter and area. Format your output to two decimal places A sample output is as follow: Testing 2 circles of same radius Two objects have equal area Testing 2 circles of different radius: The returned larger object is Circle Object The area is 28.27 The radius is 3.00 The perimeter is 18.8.5 Testing 2 rectangles of different sizes The returned larger object is Rectangle Object

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

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions