Java Reference
In-Depth Information
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.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();
Search WWH ::




Custom Search