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:
  1. The integer types are byte, short, int, and long, occupying 1, 2, 4 and 8 bytes respectively.
  2. Variables of type char occupy 2 bytes and can store a single Unicode character code.
  3. Integer expressions are evaluated using 64-bit operations  for variables of type long, and using 32-bit operations for all other integer types. You must add a cast for all assignment operations storing a result of type byte, short or char.
  4. A cast will be automatically supplied where necessary for op= assignment operations.
  5. The floating point types are float and double, occupying 4 and 8 bytes respectively.
  6. Values that are outside the range of a floating point type are represented by a special value that is displayed as either infinity or - infinity.
  7. Where the result of a floating point calculation is indeterminate, the value is displayed as NaN. Such values are referred to as Not-aNumber.
  8. Variables of type boolean can only have either the value true, or the value false.
  9. The order of execution of operators in an expression is determined by their precedence. Where operations are of equal precedence, the order of execution is determined by their associativity.