Question: Computer Science-java progam Write an abstract Java class Shape that represents a geometric shape, and create concrete (ie, non-abstract) subclasses Circle and Rectangle These classes

Computer Science-java progam
Write an abstract Java class Shape that represents a geometric shape, and create concrete (ie, non-abstract) subclasses Circle and Rectangle These classes should all be immutable. All shapes must support the fol lowing methods: Double perimeter) Returns the perimeter of the shape. For circles, this is the circumference Double area) Returns the area of the shape String toString() Returns a string showing the constructor used to con- struct the object (that is, it returns a string of the class name, an open parenthesis, the argument(s) to the constructor separated by commas, and a close parenthesis. Do not include any whitespace The Circle class should have a constructor that takes the radius as input; the Rectangle class's constructor should take a width and height as input, in that order. All these arguments should be Doubles. The key requirement is that Shape should be a Java type that supports the three methods above. For example, it must be possible to do this: Shape shape -new Circle(1.0); System.out.println("Area of unit circle is " shape.area); Note that the class of the shape variable is Shape. Declaring it to be of type Circle is not good enough. Reminder: The formulas for perimeter and area of these shapes are Shape Circle (r) Rectangle(w,h) Perimeter Area 2w + 2hwh
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
