Java Reference
In-Depth Information
*2.7
( Find the number of years ) Write a program that prompts the user to enter the
minutes (e.g., 1 billion), and displays the number of years and days for the
minutes. For simplicity, assume a year has 365 days. Here is a sample run:
1000000000
Enter the number of minutes:
1000000000 minutes is approximately 1902 years and 214 days
*2.8
( Current time ) Listing 2.6, ShowCurrentTime.java, gives a program that displays
the current time in GMT. Revise the program so that it prompts the user to enter
the time zone offset to GMT and displays the time in the specified time zone. Here
is a sample run:
Enter the time zone offset to GMT:
The current time is 4:50:34
-5
2.9
( Physics: acceleration ) Average acceleration is defined as the change of velocity
divided by the time taken to make the change, as shown in the following formula:
v 1 -
v 0
a
=
t
Write a program that prompts the user to enter the starting velocity in
meters/second, the ending velocity in meters/second, and the time span t in
seconds, and displays the average acceleration. Here is a sample run:
v 0
v 1
Enter v0, v1, and t:
The average acceleration is 10.0889
5.5 50.9 4.5
2.10
( Science: calculating energy ) Write a program that calculates the energy needed to
heat water from an initial temperature to a final temperature. Your program should
prompt the user to enter the amount of water in kilograms and the initial and final
temperatures of the water. The formula to compute the energy is
Q = M * (finalTemperature - initialTemperature) * 4184
where M is the weight of water in kilograms, temperatures are in degrees Celsius,
and energy Q is measured in joules. Here is a sample run:
Enter the amount of water in kilograms:
Enter the initial temperature:
Enter the final temperature:
The energy needed is 1625484.0
55.5
3.5
10.5
2.11
( Population projection ) Rewrite Exercise 1.11 to prompt the user to enter the
number of years and displays the population after the number of years. Here is a
sample run of the program:
 
Search WWH ::




Custom Search