|
|
Java Student Project |
||
|
|
|||
| Volume | |||
|
|
|
||
| Ability Level: | Beginner | ||
|
|
|
||
| Estimated Time: | 50 minutes | ||
|
|
|
||
| Objectives: | Use variables, data types, and mathematical operations in a program. | ||
|
|
|
||
| Materials & Resources: |
|
||
|
|
|
||
| Overview: | Make a program which will calculate the volume of the earth in cubic miles, the volume of the sun in cubic miles, and the ratio of the volume of the sun to the volume of the earth. The diameter of the sun is approximately 865,000 miles. The diameter of the earth is approximately 7600 miles. Use the methods in the class 'Math' to do your calculations. Treat both the earth and the sun as spheres. The volume of a sphere is given by the formula 4/3 pi r^3 where r is the radius. | ||
|
|
|
||
| Instructions: | Use this code,
inserting missing parts (read hints
below) :
// Author: Your name here
// Date: September 27, 1999
// Java Program Name and number: p3j-volume
// Gradebook Assignment Number: 6
public class Volumes
{
public static void main (String[] argv)
{
double sunDiam = 865000.0;
// declare the earth diameter value here
// The volume of a sphere = (4/3)*PI*(radius)^3
// Be careful with the 4/3 ratio - if you use integers, the result
// will be 1 instead of 1.33, and your answer will be wrong!
double earthVolume = (4.0/3.0) * Math.PI * Math.pow (earthDiam / 2,3);
// equation for the sun volume goes here
// equation for the volume ratio goes here
// Print the results
System.out.println ("Program - Volume by ....... on .... ");
System.out.println ("");
System.out.println ("This program calculates the volume of the earth in cubic");
System.out.println ("miles, the volume of the sun in cubic miles, and the ratio");
System.out.println ("of the volume of the sun to the volume of the earth. ");
System.out.println ("");
System.out.println ("The Earth's volume is " + earthVolume + " cubic miles.");
// Enter command lines to print out the other two.
}
}
|
||
|
|
|
||
| Hints: | Some important points
to recall in doing this project:
|
||