Print the requested details of a spherical cone to the screen.

*Textbook:* 2.4; 3.5

*New concepts:* operators (again), expressions; `Math`

methods and constants.

You will be calculating the dimensions of a spherical cone, which is essentially a cone with a spherical cap on its base (think of an ice cream cone).

Your program should start with two variables: a cone base radius (*r*) and a cone height (*c*). (Note that these are slightly different variables than those described in the linked resource).

Using these two variables, then calculate:

- slant height (
*s*):*√(r*^{2}+ c^{2}) - volume:
*2/3 * πs*^{2}(s - c) - surface area:
*πs(2(s - c) + r)*

Use only `double`

variables (not `int`

s). For π, use the pre-defined Java constant `Math.PI`

. You may create additional variables as needed (such as for the slant height, which is needed in later calculations). However all output/results should change appropriately when *only* the initial values of the radius and height are changed.

Print out the radius and the result of each of the above calculations. Print one result per line. Be sure to label what each value is in your output. Thus, your output should be formatted something like this:

For a spherical cone with radius 3.0 and height 4.0: Slant height = 5.0 Volume = 52.35987755982988 Surface area = 78.53981633974483

**When you're done:** submit your code with the radius initialized to 10.0 and height to 24.0.

Upload your

file to Tamarin.
*Username*A02.java

- 1 - Compiles
- Your program compiles successfully (no errors)
- 1.2 - Variables
- You use a variable, not a literal, for the radius and height in all your calculations and printing (0.7). You display the value of the radius and height before you do the rest of the calculations (0.5).
Results should still be correct if
*only*the value of radius and/or height variables are changed. - 1.8 - Calculations
- Program displays the correct results of the 3 additional calculations (with r=10.0, c=24.0), properly labelled, one per line. (0.6 each)

- So wait--the program I'm submitting is not going to have the same output as shown above?
- Correct. The example above shows how your output should be formatted--each number labelled as to what it is, with one result printed per line. The actual numbers shown, however, will be different for your submission. All the details above are for a cone of r = 3.0 and c = 4.0. When you change your code to instead initialize your radius variable to 10.0 and your height to 24.0, all of your calculation/results should change accordingly.
The reason I'm having you make this change is just as a check for you to make sure that your output really relies only on the radius and height variables, and not on a few literals accidentally scattered here and there throughout your code. That's the whole point of a variable: change the value in the variable, and your program's behavior/output changes accordingly (hopefully correctly).

- The formulas given don't match those of the linked resource.
- Since the slant height is actually dependent on the other two values, I wanted you to use only two input variables for this assignment. Here's a mapping between all the variable names floating around:
- slant height of cone = radius of sphere = R = s
- height of spherical cap = h = (s - c)
- height of cone = R - h = c
- radius at cone base = radius of spherical cap base = r = r

- How do I use the value of π?
- Use
`Math.PI`

and it will give you a very precise version of π. So, for example:double circumference = 2 * Math.PI * radius;

where`radius`

is a variable you already declared and initialized before this line. - How do I compute the square root (√)?
- Use
`Math.sqrt()`

. So, to take the square root of 9, you could do something like this:double answer = Math.sqrt(9);

You could also replace the literal 9 with a variable or a longer expression. - And how do I compute powers, such as r
^{3}? - There is a way to do it using the
`Math.pow()`

function, such as in`int cubeVolume = Math.pow(side, 3)`

. However, it's not really necessary for this assignment. You can just compute it "manually":`radius * radius`

. - My volume calculation isn't coming out correctly!
- Be careful of integer math. Remember that
`System.out.println(1 / 3);`

prints out`0`

, not`0.3333333`

. So you want to use double (floating point) literals, rather than int (integer) literals here.