Consider the following JAVA program in which the statements are in the incorrect
ID: 3734371 • Letter: C
Question
Consider the following JAVA program in which the statements are in the incorrect order. Rearrange the statements so that the program prompts the user to input the height and the radius of the base of a cylinder, and outputs the volume and surface area of the cylinder. Also modify the relevant output statements to format the output to two decimal places.
public class Ch3_PrExercise2
{
public static void main(String[] args)
{
} import }
System.out.print("Enter the height of the cylinder: ");
radius = console.nextDouble();
System.out.println();
static Scanner console = new Scanner(System.in);
System.out.println("Volume of the cylinder = " + PI * Math.pow(radius, 2.0) * height);
System.out.print("Enter the radius of the base of the " + " cylinder: ");
height = console.nextDouble();
System.out.println();
double height;
double radius;
System.out.println("Surface area: " + (2 * PI * Math.pow(radius, 2.0)) + (2 * PI * radius * height));
static final double PI = 3.14159; java.util.*;
}
}
import java.util.*;
This is what I have come up with so far...please help.
The last two highlighted two areas I can't get pass through
import static java.time.Clock.system;
import java.util.*;
public class Lab2_Exercise2
{
//declare the static fields out of the main method
static Scanner console = new Scanner(System.in);
static final double PI=3.14159;
//start main method
public static void main(String []args)
{
//declare the variables first
double height, radius;
//prompt user to enter height of the cylinder
System.out.print ("Enter the height of the cylinder:");
//get and store the height
height = console.nextDouble();
System.out.println();
//prompt user to enter radius
System.out.print ("Enter the radius of the base of the cylinder:");
//get and store the radiu
radius = console.nextDouble ();
System.out.println ();
/*calculate volume of the cylinder and display the result up to two decimal places*/
System.out.println ("Volume of the cylinder ="+PI * Math.pow (radius, 2.0 * height);
/*calculate surface area of the cylinder and display the result up to two decimal places*/
System.out.printin ("Surface area:" +(2* PI* Math.pow(radius, 2.0)) +( 2*PI * radius * height));
}
// end of main method
}
//end of exercise
Explanation / Answer
import java.util.*;
public class Lab2_Exercise2
{
//declare the static fields out of the main method
static Scanner console = new Scanner(System.in);
static final double PI=3.14159;
//start main method
public static void main(String []args)
{
//declare the variables first
double height, radius;
//prompt user to enter height of the cylinder
System.out.print ("Enter the height of the cylinder:");
//get and store the height
height = console.nextDouble();
System.out.println();
//prompt user to enter radius
System.out.print ("Enter the radius of the base of the cylinder:");
//get and store the radiu
radius = console.nextDouble ();
System.out.println ();
/*calculate volume of the cylinder and display the result up to two decimal places*/
System.out.println ("Volume of the cylinder ="+(PI * Math.pow (radius, 2.0 * height)));
/*calculate surface area of the cylinder and display the result up to two decimal places*/
System.out.println("Surface area:" +(2* PI* Math.pow(radius, 2.0)) +( 2*PI * radius * height));
}
// end of main method
}
//end of exercise
/*
Sample run:
Enter the height of the cylinder:5.6
Enter the radius of the base of the cylinder:5
Volume of the cylinder =2.1164770054443035E8
Surface area:157.0795175.92904
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.