Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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: :="" := | := t Crectangle>=1 == c := number> Note that is anything that Java can interpret as a number. Here is an example with a circle, a triangle, a rectangle, and another circle: > java Main "c 1.0 0.2 4.4" "t 0.4 5.3 0.4 5.6 3.0 1.2" " 3.0 -3.4 2.3 0.9" "CO 10." The total area for the 4 objects is 377.75 units squared. 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: :="" := | := t Crectangle>=1 == c := number> Note that is anything that Java can interpret as a number. Here is an example with a circle, a triangle, a rectangle, and another circle: > java Main "c 1.0 0.2 4.4" "t 0.4 5.3 0.4 5.6 3.0 1.2" " 3.0 -3.4 2.3 0.9" "CO 10." The total area for the 4 objects is 377.75 units squared

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 Processing

Authors: David M. Kroenke

12th Edition International Edition

1292023422, 978-1292023427

More Books

Students also viewed these Databases questions

Question

13-1 How does building new systems produce organizational change?

Answered: 1 week ago

Question

13-4 What are alternative methods for building information systems?

Answered: 1 week ago