Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab 3 Question 4: The statements in the following program are in incorrect order. Rearrange the statements so that it prompts the user to input

Lab 3

Question 4:

The statements in the following program are in incorrect order. Rearrange the statements so that it prompts the user to input the shape type (rectangle, circle or cylinder), and the appropriate dimension of the shape. The program then outputs the following information about the shape! For a rectangle, it outputs the area and perimeter; for a circle. it outputs the area and circumference; and for a cylinder, it outputs the volume and surface area. After rearranging the statements, your program should be properly indented.

image text in transcribedimage text in transcribed
Programming Exercises | 243 System. out. printin () ; System. out. printf ("Area of the rectangle - 8.2fon", (length * width) ) ; System. out. printf (" Surface area of the cylinder: $.2fin", (2 * PI * radius * height + 2 * PI *Math. pow (radius, 2.0) )) , else System. out. printin ("The program does not handle " + shape) ; static Scanner console - new Scanner (System. in) ; static final double PI - 3.1416; import java. util.*;242 1 Chapter 4: Control Structures |: Selection public class Ch4_PrExercised public static void main (String[ ] args) System. out. print ("Enter the shape type: (rectangle, +" circle, cylinder) ") ; shape - console. next () ; System. out. printIn () ; String shape if (shape. compareTo ("rectangle") = 0) 1 System. out. print ("Enter the height of the cylinder: "); height - console. nextDouble () ; System. out. printin () ; System. out. print ("Enter the width of the rectangle: ") ; width - console. nextDouble () ; ; System. out.printin () ; System. out. printf ("Area of the circle - $.2fin", (PI * Math. pow (radius, 2.0) )) ; System. out. printf ("Perimeter of the rectangle = 1.2fin", (2 * (length + width) ) ); double length; double width; else if (shape. compareTo ("circle") == 0) 1 System. out. print ("Enter the length of the rectangle: ") ; length = console.nextDouble () ; ; System. out. printin () ; System. out. printf ("Volume of the cylinder - $. 2fen", (PI * Math. pow (radius, 2.0)* height) ) ; System. out. printf ("Circumference of the circle: $.2fin", (2 * PI * radius) ) ; alse if (shape. compareTo ("cylinder") -- 0) double height; double radius; System. out. print ("Enter the radius of the circle: ") ; radius - console , nextDouble () ; ; System, out .printin () ; System. out . print ("Enter the radius of the base of " "the cylinder: ") radius - console. nextDouble ()

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions