Question: Write a Java program that asks your user to enter the height of a cylinder and then asks them to enter the radius of a

  • Write a Java program that asks your user to enter the height of a cylinder and then asks them to enter the radius of a cylinder. The program should then calculate the surface area of a cylinder with those dimensions and output the result.

Details:

  • The formula for the surface area of a cylinder is: 2 * PI * radius *(height + radius)
    • You must code this formula up so that your program produces the correct surface area value no matter what height and radius are entered.
  • Use double numbers in your calculations for precision since you are working with PI which has decimals.
    • PI must be correctly declared and initialized as a static constant.
    • radius and height should be double variables
  • The values for the radius and the height should be read in from your user as Strings using a Scanner then parsed to doubles.
    • Do not use any method other than nextLine() to read from the user
    • Your program will crash if the user enters something other than a number, this is okay for now. We will learn how to fix this soon.
  • Use variable names/constant names that are meaningful
  • The output should be displayed in an attractive, user-friendly manner.
    • Example program output: (program output in black, user's input in orange)

*Using only import java.util.scanner;

*use System.out.printf and format the output area to 2 decimal places *Do not hard code.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!