JAVA A company needs to develop an object-oriented library with a few Java classes for the following task. Overall, they want the classes to model the geometric shapes and calculate their areas. These geometric shapes include Square, Rectangle, Circle, and Triangle. The above four shapes share common attributes such as name and color. The area of a shape can be calculated by using a method area( ) which can be implemented only until the exact shape is known. Different shapes need a different area( ) method. 1) Design a Java abstract class called Shape to model this situation, which will serve as a parent class. Write its code; 2). All the above shapes should be drawable by the users by calling the draw( ) method. Different shapes are drawn differently. You should design a Java interface named Drawable to provide this method for the shape classes to implement in their own ways. Write its code; 3). Write the code for the four classes: Square, Rectangle, Circle, and Triangle. Note: • You should decide what data members you should have for each class based on mathematical concepts; • You should determine the relationship between the four classes and Drawable and Shape; • You should provide all constructors, get/set methods, the draw( ) method, the area( ) method, and toString() methods. • Use the following formulas for calculating areas of the four shapes: o Area of Square = side x side; o Area of Rectangle = length x width; o Area of Circle = PI x radius x radius; o Area of Triangle = 0.5 x base x height; • In the test driver code, create an object of each of the four classes with some dimension data, put the objects in an array, and pass the object array to a method called displayShapeAreas(Shape[ ] shapeArray) and have their areas displayed.

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter10: Introduction To Inheritance
Section: Chapter Questions
Problem 19RQ
icon
Related questions
Question

JAVA

A company needs to develop an object-oriented library with a few Java classes for
the following task. Overall, they want the classes to model the geometric shapes and calculate
their areas. These geometric shapes include Square, Rectangle, Circle, and Triangle.
The above four shapes share common attributes such as name and color. The area of a shape
can be calculated by using a method area( ) which can be implemented only until the exact
shape is known. Different shapes need a different area( ) method.
1) Design a Java abstract class called Shape to model this situation, which will serve as a parent
class. Write its code;
2). All the above shapes should be drawable by the users by calling the draw( ) method.
Different shapes are drawn differently. You should design a Java interface named Drawable
to provide this method for the shape classes to implement in their own ways. Write its code;
3). Write the code for the four classes: Square, Rectangle, Circle, and Triangle.
Note:
• You should decide what data members you should have for each class based on
mathematical concepts;
• You should determine the relationship between the four classes and Drawable and Shape;
• You should provide all constructors, get/set methods, the draw( ) method, the area( )
method, and toString() methods.
• Use the following formulas for calculating areas of the four shapes:
o Area of Square = side x side;
o Area of Rectangle = length x width;
o Area of Circle = PI x radius x radius;
o Area of Triangle = 0.5 x base x height;
• In the test driver code, create an object of each of the four classes with some dimension
data, put the objects in an array, and pass the object array to a method called
displayShapeAreas(Shape[ ] shapeArray) and have their areas displayed.

Expert Solution
steps

Step by step

Solved in 8 steps with 1 images

Blurred answer
Knowledge Booster
Development strategies
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,