Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assume that you are writing a console-based Java application that uses the type of shape (assume rectangle, square, or circle) and computes the area and

image text in transcribedimage text in transcribed

Assume that you are writing a console-based Java application that uses the type of shape (assume rectangle, square, or circle) and computes the area and perimeter (circumference) of that shape. The Java class Math has constant Pi (Math.PI). Show the UML diagram for class Shape including appropriate (only) getter and setter methods, and write the Java code for class Shape that has instance variables as follows String variable shapeType (rectangle, square, circle), and double length, width, and radius for the measurements. For the square only length is used Output instance variables including double area and perimeter. For the rectangle area length *width, and perimeter 2 * (length width); For the square area length*length, and perimeter 4*length; For the circle area -pi radius 2, and perimeter 2 pi * radius. Method computeShape0 in class Shape performs the computations using the input instance variables and setting the output instance variables (area and perimeter). The method does not return a value Class Shape does not perform any input or output. All input and output is in class ShapeDriver that has method main)-you need to write this method as well. In addition to processing individual shape entries you need to accumulate them in an array of type Shape. At the beginning of the main) method prompt the user for the maximum number of shapes to process. After processing the individual shapes, accumulating them in the array of type shape, output all array elements in tabular format with proper heading. You need to account for the possibility of the user entering a bad shape type or continuing beyond the maximum number of shapes. Sample input and output: OS401 Assignment number 5 - Shape Area-Perimeter calculator Enter maximum number of shapes: Enter type of shape (S for square, R for rectangle, and C for circle: Enter length/width of square: 1e Shape type s, length 10.8, width e.8, radius e.e, the area is 100.6 , and the perimeter is 40.e Do you wish to continue (y)? Enter type of shape (S for square, R for rectangle, and C for circle: Enter length of rectangle: 18 Enter width of rectangle: 20 Shape type r, length 10.8, width 20.6, radius 8.0, the area is 260.8 , and the perimeter is 68.8 Do you wish to continue (y)? Enter type of shape (S for square, R for rectangle, and C for circle: Bad shape type: x Enter type of shape (S for square, R for rectangle, and C for circle: Enter radius of circle: 10 Shape type c, length .0, width 0.0, radius 10.8, the area is 314.1592653589793 , and the perimeter is 62.83185307179586 Do you wish to continue (y)? Number of shapes processed is 3 number shape length width radius area perimeter 16.0 0.e. 100. 40.0 16.0 20.0 e. 200. 60.0 0.0 .8 18.0 314.1592653589793 62.83185307179586 End Shape Area-Perimeter calculator

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

Main Memory Database Systems

Authors: Frans Faerber, Alfons Kemper, Per-Åke Alfons

1st Edition

1680833243, 978-1680833249

More Books

Students also viewed these Databases questions