Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the inheritance hierarchy in the figure on the next page. The top of the hierarchy begins with class Shape, which is extended by subclasses

Consider the inheritance hierarchy in the figure on the next page. The top of the hierarchy begins with class Shape, which is extended by subclasses TwoDShape and ThreeDShape, corresponding to 2D and 3D shapes, respectively. The third level of this hierarchy contains specific types of 2D and 3D shapes such as circles and spheres, respectively. The arrows in the graph represent isa (inheritance) relationships and the boxes represent classes. For example, a Triangle isa TwoDShape, which in turn isa Shape. Likewise, a Sphere is a ThreeDShape, which in turn is a Shape.

Your task is to implement the entire hierarchy of classes in the figure below. Each two-dimensional shape should contain a getArea() method to calculate the area of the shape. Each three-dimensional shape should contain methods getArea() and getVolume() to calculate the area and volume of the shapes.

Create a program that reads in a set of shape specifications from a text file. It is up to you to design each shape specification. For example, a circle will likely need an (x,y) co-ordinate for its center in addition to the length of the circles radius. So in the file you might specify a circle as:

circle 10 20 5

This would be interpreted as a circle object whose center is in co-ordinate (10,20) and has a radius of length 5. The specifications for other shapes are similar in concept. To simplify things your input file may assume that each line in the input text file corresponds to one shape.

The shapes, once read in from the input text file should be stored in an array of Shapes. The program should open an output text file, loop through the Shapes array, and for each shape write to the output file a text description of the object (e.g., circle, square) and its area, and optionally, its volume if it is a three-dimensional shape. Again you may assume that the output file stores one shape per line.

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 Security

Authors: Alfred Basta, Melissa Zgola

1st Edition

1435453905, 978-1435453906

More Books

Students also viewed these Databases questions

Question

How do we organise for international logistics?

Answered: 1 week ago

Question

What are the logistics implications of internationalisation?

Answered: 1 week ago