Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 3: Shape (10 points) (Software Design) Create an abstract class that represents a Shape and contains abstract method: area and perimeter. Create concrete classes:

Problem 3: Shape (10 points) (Software Design) Create an abstract class that represents a Shape and contains abstract method: area and perimeter. Create concrete classes: Circle, Rectangle, Triangle which extend the Shape class and implements the abstract methods. A circle has a radius, a rectangle has width and height, and a triangle has three sides. Software Architecture: The Shape class is the abstract super class and must be instantiated by one of its concrete subclasses: Circle, Rectangle, or Triangle, which extends it. UML Object Diagram Shape CircleRecangleTriangle UML Class Diagram: Shape +area(): double + perimeter): double italicized class/method names within UML Class Diagram indicate abstract class/methods Shape Method API: Modifier and Type Method and Description abstract doublearea() Returns the area of this shape abstract double perimeter() Returns the perimeter of this shape UML Class Diagram: Circle - radius: double constructor (radius: double) + area): double tostring(): String +constructor) +perimeter(): double Italicized class/method names within UML Class Diagram indicate abstract class/methods Circle Constructor Summary: Constructor Circle (double radius) Circle() Description Creates a Circle with given radius Creates a Circle with radius 1 SalaryEmployee Method API: Modifier and Type Method and Description double area) Returns Math.PI (radius) perimeter() Returns 2 Math.PIradius tostring() Returns the String "Circle" double String UML Class Diagram: Rectangle width: double - length: double +constructor (width: double, length: double) +constructor () +area(): double + perimeter(): double toString(): String Italicized class/method names within UML Class Diagram indicate abstract class/methods Rectangle Constructor Summary: Constructor Rectangle (double width, double length) Creates a Rectangle with given length, width Rectangle() Description Creates a Rectangle with width 1, length 1 Rectangle Method API: Modifier and Type Method and Description double area() Returns width * length perimeter() Returns 2" (width + length) toString() Returns the String "Rectangle" double String UML Class Diagranm Triangle -a: double -b: double -C: double +constructor (a: double, b: double, c: double) +constructor() +area(): double +perimeter() double + toString(): String Italicized class/method names within UML Class Diagram indicate abstract class/methods Triangle Constructor Summary Constructor Triangle(double a, double b, double c) Creates a Triangle with given sides a, b, c Triangle() Description Creates a Triangle with all sides- 1 Triangle Method API Modifier and Type Method and Description double area() Returns area of triangle using heron's formula perimeter() Returns a b c toString() Returns the String "Triangle" double String Tester Files: Use the TestShape.java file to test your implementation. Compare your results with the TestShape.txt file Sample Method Calls Sample Method Results Shape[] shapesnew Shape[3]; shapes [0] new Circle(3); shapes [1]new Rectangle(4,2); shapes [2]-new Triangle (1,2,3); "Circle: area: 28.3, perimeter: 18.81n" "Rectangle: area: 8.0, perimeter: 12.01n" "Triangle: area: 0.0, perimeter: 6.01n" for (Shape polygon shapes) double areapolygon.area) double perimeter- polygon.perimeter); System .out.printf("%s: area: %.elf perimeter : %.81f ", polygon, area, perimeter)

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_2

Step: 3

blur-text-image_3

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

Combinatorial Testing In Cloud Computing

Authors: Wei-Tek Tsai ,Guanqiu Qi

1st Edition

9811044805, 978-9811044809

More Books

Students also viewed these Programming questions