Question
Define a class Shape with an abstract method CalculateArea(). Define two additional classes for a triangle and a rectangle with fields width and height (values
Define a class Shape with an abstract method CalculateArea(). Define two additional classes for a triangle and a rectangle with fields width and height (values being set through appropriate constructors), which implement CalculateArea(). This method has to return the areas of the rectangle (height*width) and the triangle (height*width/2). Define another class for a circle with an appropriate constructor, which initializes the two fields (height and width) with the same value (the radius) and implements the abstract method for calculating the area.
Create an array of different shapes and calculate the area of each shape in another array.
Step by Step Solution
3.43 Rating (153 Votes )
There are 3 Steps involved in it
Step: 1
Mainjava public class Main public static void mainString args create instance of each class Circle c...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get StartedRecommended Textbook for
Introductory Classical Mechanics
Authors: David Morin
1st edition
9780511808951, 521876222, 978-0521876223
Students also viewed these Programming questions
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
View Answer in SolutionInn App