Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Methods Page 457 Chapter 7: User-Defined Methods (This problem is also in your book) Please complete Programming Exercise #5 (I copy-and-pasted it below) Key statement

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Methods Page 457 Chapter 7: User-Defined Methods (This problem is also in your book) Please complete Programming Exercise #5 (I copy-and-pasted it below) 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_Prxercise statie Scanner console - new Scanner(System.in) public statie 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("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.nextDouble(); height - console.nextDouble(); System.out.println(); System.out.printf ("Area - 8.21n", circle (length, height)); ALEKS - AX 30 3329978 Bowie Statex Testing Sex G precise -xythos.content blackboardcdn.com/6c1c67a3c99fc/3281610?X-Blackboard-Expiration=16134120000008X-Blac.. 2 / 3 100% + System.out.print("Area - 3.2fin". circle(length, height) break; case 3: double length, width System.out.print("Enter the radius of the circle: "); radius - console.nextDouble(); System.out.printin: System.out.printf ("Area - 4.248", rectangle (radiun) 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.print("Volume - 1.2", cylinder (radius, height) break; default: system.out.println("Invalid choice!"); 1 witch (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 ) return Math.PI. r. w public static double cylinder (double br, double h) return Math.PI DR. BR. 17

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

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions