The following is designed to find the area of a rectangle , the area of a circle
ID: 3632552 • Letter: T
Question
The following is designed to find the area of a rectangle , the area of a circle, or volume of a cylinder. However , the statements are in the incorrect order; method calls are incorrect; the logical expression in the while loop is incorrect ; and method definitions are incorrect. Rewrite the program so that works correctly. The program must be properly indented.Import java.util.*;
Public class Ch_7PrExercise5
{
static Scanner console = 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 a 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 = %.2f%n”,
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 = %.2f&n", rectangle (radius));
break;
case 2:
System.out.print("Enter the length and width "
+ "of the rectangle: ");
length = console.nextDouble();
width = cosole.nextDouble();
System.out.println();
System.outprintf("Volume = %.2f%n",
cylinder(radius, height));
break;
default:
System.out.println("Invalid choice!");
}
switch (choice)
}
System.out.println(“To run the program enter: “);
System.out.println(“1: To find the area of a circle. “);
System.out.println(“2: To find the area of a 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 * bR * bR * 1;
}
}
Explanation / Answer
Any way, i managed to fix it: #include #include using namespace std; const double PI = 3.01419; double rectangle(double l, double w); double cylinder(double Br, double h); double circle(double r); int main() { double radius; double height; int choice = 0; coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.