CMIS 102
Homework
Create an applet program that calculates the areas and volumes of
various 3D geometric objects: cylinders, cones, cubes and spheres.
The formula for the area of a cylinder is:
(two times pi times radius times height)
plus
(two times pi times (radius squared))
the formula for the area of a sphere is:
four times pi times (radius squared)
formula for area of a cone:
(pi times radius times (square root of (radius squared) plus (height squared)))
plus
(pi times (radius squared))
formula for area of a cube:
six times (side length squared) Let the side length be "height"
Volume of sphere:
four-thirds times pi times (radius cubed)
Volume of cylinder:
pi times (radius squared) times height
Volume of cone:
one-third times pi times (radius squared) times height
Volume of a cube:
height cubed
In the init method input from the user the radius and height of the
solids. Use the same values for all the solids (input them only once).
You are writing one program that does all 8 calculations.
Use doubles for the numeric variables. Have a variable for each of
the 8 areas and volumes (i.e. 8 variables, well-named).
Output the results in the paint method using drawString.
Display the results tabularly like the following:
------------------------------------------------
radius xx
height xx
Solid Area Volume
----- ----- ------
cone xx.xx xx.xx
sphere x.xx x.xx
cylinder xx.xx x.xx
cube x.xx x.xx
where the x's are the actual values. Don't worry about aligning the
columns perfectly.
Use the setFont method to display in a 22 bold courier font.
Hint: don't write all this at once; build it up piece by piece.
Create the basic input and one output of this applet first, then when
that works add some of the other geometric objects, and the display
font.
Print the Java source code file and turn in.
Email the source code to your instructor.
Here's an example to check your work by:
height 1 and radius 1
cone surface area is 7.584
sphere surface area is 12.566
cylinder surface area is 12.566
cube surface area is 6
cone Volume is 1.047
sphere Volume is 4.189
cylinder Volume is 3.142
cube Volume is 1