JAVA Put all of the following in ONE program. Use comments to delineate each step. For example:
Question:
JAVA
Put all of the following in ONE program. Use comments to delineate each step. For example:
public static void main( String astrCommandLine[ ] )
{
// --------------------------------------------------------------------------------
// Problem 1: Age in seconds
// --------------------------------------------------------------------------------
< your code here>
...
// --------------------------------------------------------------------------------
// Problem 2: Volume of Sun, Earth and ratio of the two
// --------------------------------------------------------------------------------
< your code here>
...
// --------------------------------------------------------------------------------
// Problem 3: Number of molecules in 2.45 quarts of water.
// --------------------------------------------------------------------------------
< your code here>
...
}
You cannot use variables of data type double for any of the problems. You must use int and float.
Step 1
- Calculate your age in seconds by:
- Calculating the number of seconds in a day.
- Calculating how many days you've been alive by multiplying the number of years since you were born by 365.
- Multiply the number of days you've been alive by the number of seconds per day and print the result.
Step 2
- The diameter of the Sun is approximately 865,000 miles. The diameter of the Earth is approximately 7600 miles. Use methods in the Math library (e.g. Math.pow( base, exponent ) ) to calculate:
- The volume of the Sun in cubic miles. You'll need to Google for the calculation for volume of a sphere if you don't remember it or you can look in a math book.
- The volume of the Earth in cubic miles
- The ratio of the volume of the Sun to the volume of the Earth
Step 3
- Calculate the number of molecules in 2.45 quarts of water. The mass of a single molecule of water is about 3.0 x 10-23 grams. A quart of water is about 950 grams.
Step 4
- Be sure to test your answers!!! How do you do that? Well, that's part of the problem. Hint: how do you know the answers the computer gives you are correct? Try computing the answer with a calculator (Start / All Programs / Accessories / Calculator and use the Scientific View).
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates