Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please use java Your main should produce the preceding output via the following code: public static void main(String args[]) { Shape shape[] = new Shape[args.length];
Please use java
Your main should produce the preceding output via the following code:
public static void main(String args[]) { Shape shape[] = new Shape[args.length]; /* Some initialization from the args ... */ System.out.printf("The total area for the %d objects is %1.2f units squared. ", shape.length, AreaCalculator.calculate(shape)) }Shapes Inheritance and dynamic dispatching The Shape class represents a geometric figure in some coordinate position. Shape allows for finding out its position and area with the methods Point position() and double area(). Point is a class that can represent a two-dimensional coordinate. The Shape class must be an abstract class, from which you will derive three subclasses: Triangle, Rectangle, and Circle to represent different kinds of shapes. Pick some definition of position() that makes sense in order for the equalstoo, which is described below, will work as we might expect. Something like centroid would be a good choice. 1. Implement the class Point. 2. Implement the class Shape. 3. Implement the three subclasses of Shape to represent triangles (with three points), rectangles (points for upper-left and lower-right corners), and circles (with a center and radius). Each of Triangle, Rectangle, and Circle should inherit from the class Shape and define area() appropriately. 4. Implement a class AreaCalculator with one static method calculate (Shape() shapes) that will calculate the total area of an array of shapes. 5. Implement a class Main, of which the main() method will accept command line arguments as input. It should process the input string, constructing shapes, and storing them in an array. The input is given according to the following specification:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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 Started