Assignment 09


Write a separate class to use to solve a problem. This is essentially an extension of A02, only this time defining the spherical cone as its own class with instance methods.

Concepts: Objects, instance methods
Textbook: 4.4


You are going to write a SphericalCone class, test that it is correct, and then use that class to solve a problem involving ice cream cones. Do this in the following order.

Step 1:

Write a public class named SphericalCone. Put this in its own file. It should contain the following three instance methods:

Your methods must much these signatures exactly (though you can change the variable names r and c, if you like). Note that each method takes the same two parameters: the radius of the cone base and the cone height, in that order.

The necessary formulas were given in A02. Ideally, the calculation of each detail will occur in only one place in your code. Remember that you can call one method from another. This would be handy for getting the slant height when computing the volume or surface area.

Your methods should return the correct values. They should not print anything to the screen.

Step 2: Testing

The primary reason for writing methods is so that you can easily reuse chunks of code. It reduces errors and makes code easier to maintain if you can avoid duplicating code.

But the separation of code into small, independent modules has additional benefits. It can make the code more readable overall. And you can then unit test each of these small pieces to know they are correct. This helps greatly when debugging, especially for larger programs.

Here is a sample unit test for your cone:

Download this file and put it in the same directory as your file. You should then be able to compile and run SphericalConeTester to ensure that all your methods have the correct signatures and return the correct values.

Step 3: Main program (

Now that you know your SphericalCone is correct, you could reuse it in a number of different programs. Here is one such program:

An ice cream company makes three different sizes of pre-packaged ice cream cone: small, medium, and large. Since these are pre-packaged, there is not quite as much ice cream as on a regular cone; therefore, they are actually shaped as spherical cones.

The dimensions are as follows:

The company is interested in knowing how much packaging (surface area) and ice cream (volume) goes into each of their cones.

Write a program that clearly prints the surface area and volume for each of these three spherical cone sizes. Create a single instance of your SphericalCone class and call its methods to calculate this. Then also print the total volume consumed if one ate all three ice cream cones.

There is no user input for this program.

Sample Output

SMALL cone:
Volume = 68.48657702033661 cm^3
Surface area = 100.88951136341649 cm^2

MEDIUM cone:
Volume = 118.34480509114118 cm^3
Surface area = 145.28089636331964 cm^2

LARGE cone:
Volume = 353.95277230445 cm^3
Surface area = 285.8849314766712 cm^2

Total volume: 540.7841544159278 cm^3

What to Submit

You are going to submit only your UsernameA09 and SphericalCone classes.

Normally, each Java class should be in its own file. However, Tamarin only takes a single file per submission. So you are going to move your SphericalCone class into your file. Paste the entire SphericalCone class after the last } of the UsernameA09 class. (Please make sure you don't put one class within another!)

Java will allow you to have only 1 public class per file though, so you also need to remove the word public from the SphericalCone class. (Leave the public modifier on all your methods, though.)

So, your file should now be structured like this:

public class UsernameA09 {
  //... your main method in here ...

class SphericalCone {
  //... your three methods in here ...

You may want to try deleting all your .class files, and then compiling and running your one more time before you submit it, just to make everything still works correctly.

Then, upload your complete file to Tamarin.

Grading [5 points]

1 - Compiles
Your program compiles successfully (no errors)
2.5 - SphericalCone
Class needs to be named correctly. Methods are named as above and each returns the correct result when passed a radius and height value (given in that order) (0.6 each). Methods do not print to the screen (0.5). Methods are instance methods (not static) (0.2).
1.5 - UsernameA09
Program clearly prints the correct volume and surface area of the three cones (small, medium, large) with the dimensions given above (1.0). Also prints the total volume of the three cones (0.3). Creates and uses a SphericalCone object to do this (0.2).