Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Key statement below : Rewrite the program so that it works correctly. The following program designed to find the schede, the ander the volume of

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Key statement below : "Rewrite the program so that it works correctly. The following program designed to find the schede, the ander the volume of det. However the main the incorrect anderi) the method cali e corot the local son in the while loupect, and (d) method de incorrect. Rewrite the program so that it comes Your pro must be prupedy indented. (Note that the program memorie allow the mer to run the programlong them whe) ne coole System plesati dirilla Statius System.out.print procese the angle, the leader." System.out.println(the parentes System.out.printit te find the sot rectasis. System.out.println(": to find the world. System.out.println-1: Te teminate the choice - cele.net System.out.printinos int choice white choice System.out.print("Enter the rate of the base and the height of the cylinder) radius - console.sextDouble height - least Double System.out.printin System.out.print"Ares - 2 circle length it can 3 double Length, width System.out.print"inter the radius of the circler") radius - console.nextDouble) System.out.println System.out.print("res- 2. rectangle tradius) ca 2: 3 of 3 Stut.print the tea and the width length - than with cholestDochter System.out. System.out.println"atta System.out.printo the programeters System.out.2: To rind the sucre System.out. So that Systet. Toid the world. yout.prin toate the program che 1 1 este de 1 Copy and paste your code and output to MS-Word. **** UPLOAD TO BLACKBOARD DROP BOX Key statement below : "Rewrite the program so that it works correctly.' 5. The following program is designed to find the area of a rectangle, the area of a circle, or the volume of a cylinder. However, (a) the statements are in the incorrect order; (b) the method calls are incorrect; (c) the logical expres- sion in the while loop is incorrect; and (d) method definitions are incorrect. Rewrite the program so that it works correctly. Your program must be properly indented. (Note that the program is menu driven and allows the user to run the program as long as the user wishes.) import java.util.*; public class Ch7_PrExercise5 { static Scanner console = new Scanner (System.in); public static void main(String[] args) { double radius; double height; System.out.println("This program can calculate + "the area of a rectangle, the area" + "of a circle, or volume of a cylinder."); System.out.println("To run the program enter: "); System.out.println("1: To find the area of rectangle."); System.out.println("2: To find the area of a circle."); System.out.println("3: To find the volume of a cylinder."); System.out.println("-1: To terminate the program."); choice - console.nextInt(); System.out.println(); int choice; while (choice - -1) ( { case 1: System.out.print("Enter the radius of the base and + "the height of the cylinder: "); radius - console.next Double(); height - console.nextDouble(); System.out.println(); System.out.printf("Area - 4.2in", circle (length, height)); break; case 3: double length, width; System.out.print("Enter the radius of the circle: "); radius - console.nextDouble(); System.out.println(); System.out.printf ("Area - 1.28tn", rectangle (radius)); break; case 2: System.out.print("Enter the length and the width + "of the rectangle: "); length - console.nextDouble(); width - console.nextDouble(); System.out.println(); System.out.printf("Volume - 3.2f8n", cylinder (radius, height)); break; default: System.out.println("Invalid choice!"); } switch (choice) > System.out.println("To run the program enter: "); System.out.println("2: To find the area of a circle."); System.out.println("1: To find the area of rectangle."); System.out.println("3: To find the volume of a cylinder."); System.out.println("-1: To terminate the program."); choice = console.nextInt(); System.out.println(); } public static double rectangle (double 1, double w) { return 1* r; ) public static double circle (double r) return Math.PI * r * w; } public static double cylinder (double br, double h) { return Math.PI * ER * bR * 1; } }

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

Databases A Beginners Guide

Authors: Andy Oppel

1st Edition

007160846X, 978-0071608466

More Books

Students also viewed these Databases questions

Question

LO3 Name the seven categories of HR functions.

Answered: 1 week ago