Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program Behavior The program will repeatedly process the dimensions of a cone and produce various results. For each cone, it prompt the user to enter

Program Behavior
The program will repeatedly process the dimensions of a cone and produce various results. For each cone, it prompt the user to enter the cone's radius and height. It will then calculate and print the lateral surface area, total surface area, and volume of the cone. The lateral surface area is the surface of the cone without the base and the total surface area includes the base.
Here is a sample run of the program. User input is shown in blue.
Welcome to Cone Calculator!
Enter the radius: 7.31
Enter the height: 34.6
Lateral surface area: 812.1304
Total surface area: 980.005
Volume: 1936.15
Process another cone (y or n)? y
Enter the radius: 4.72
Enter the height: 15.5
Lateral surface area: 240.2592
Total surface area: 310.249
Volume: 361.61
Process another cone (y or n)? Y
Enter the radius: -5.1
Enter the height: 12.4
Error: The radius and height must both be greater than 0.
Please reenter.
Enter the radius: 24.7883
Enter the height: 52.903
Lateral surface area: 4549.6362
Total surface area: 6480.019
Volume: 34041.01
Process another cone (y or n)? n
Thanks for using Cone Calculator!
Make sure your prompts and output conform to the example above, including blank lines in the output. Use printf statements to output the lateral surface area to 4 places past the decimal point, the total surface area to 3 places, and the volume to 2 places.
Note that the input are both floating-point values.
You can assume that the user will enter numeric data for the radius and height, but you will validate the numbers. If either input value is 0 or less, print an error message as shown above and reread both values. Do not calculate cone values (area, volume) for invalid input.
When determining whether the user wants to process another cone, an input value of "y" or "Y" should be interpreted as yes. Any other input string should be interpreted as a no.
You'll need to read (consume and throw away) the newline character after the height is input BEFORE reading the string that determines whether the user wants to process another cone. If you don't, that question will be answered by the newline and interpreted as a negative response.
Program Design
Create a new BlueJ project called ConeCalculator and inside that create a class called ConeCalculator. Your class will contain two static methods: processCones and coneCalc.
The processCones method should accept no parameters and return no value. Think of this as the main driver of the program. This method should print the welcome message, read and process as many cones as the user would like, then print the final message.
The coneCalc method should accept the radius and height of one cone as parameters. It should calculate the three values for the code and print the results (using printf statements). This method returns no value.
Use the formulas below to calculate the values needed. However, use meaningful variables names in your program, not the abbreviated symbols shown in the formulas.
For a cone with radius r and height h, the slant height (s) is the length along the edge from the tip of the cone to the base:
(LOOK AT PICTURE PROVIDED)
Developing the Program
As with almost all programs: develop it in stages. Don't try to get the whole thing written before compiling and testing it. For example, you could:
Get the infrastructure of the program set up, including both methods. Print the welcome and final messages. Compile and test.
Write the contents of the coneCalc method to compute and print the values for one cone. Call it once from the processCones method with hard coded parameters. Compile and test.
Set up the Scanner object for reading input. Read some sample input values and print them back out temporarily. Compile and test.
Set up the loop in processCones that repeats until the user says they have no more cones to process. Compile and test.
Read the input values for a cone and pass them to coneCalc. Compile and test.
Check to see if the input values are invalid and print the error message if so. Make sure you do NOT process invalid input. Compile and test.
Test the program with multiple other input values, verifying the output with hand calculations.
Documentation
You need to add javadoc comments to your program, specifically above the class and above each method. The class comment must include a general description of the project, as well as an @author tag with your name and an @version tag with the date. Each method comment should include a short description of what the method does as well as @param tags for each parameter accepted by the method.
image text in transcribed

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

Big Data, Mining, And Analytics Components Of Strategic Decision Making

Authors: Stephan Kudyba

1st Edition

1466568704, 9781466568709

More Books

Students also viewed these Databases questions

Question

3. What might be the response of the attorneys to this change?

Answered: 1 week ago