Java Reference
In-Depth Information
6. Bicyclists can calculate their speed if the gear size and cadence is known. Gear size
refers to the effective diameter of the wheel. Gear size multiplied by pi (3.14) gives
the distance travelled with one turn of the pedals. Cadence refers to the number of
pedal revolutions per minute (rpm). The speed in miles per hour is calculated by
the following:
2 =
S p e e d
1
mph
60 (minutes)
(hour)
This is a program that calculates the speed for a gear size of 100 inches and a
cadence of 90 rpm. This would be considered a high cadence and a maximum gear
size for a typical bicycle. In writing your program, don't forget that the expression
1/12 will result in 0, because both 1 and 12 are integers, and when the integer
division is performed, the fractional part is discarded.
7. Write a program that outputs the number of hours, minutes, and seconds that
corresponds to 50,391 total seconds. The output should be 13 hours, 59 minutes,
and 51 seconds. Test your program with a different number of total seconds to
ensure that it works for other cases.
8. The following program will compile and run, but it uses poor programming style.
Modify the program so that it uses the spelling conventions, constant naming
conventions, and formatting style recommended in this topic.
1(ft)
12 (inches) *
1(mile)
5280 (ft) *
Gear Size (inches)
Cadence (rpm)
* p *
*
VideoNote
Solution to
Programming
Project 1.7
public class messy {
public static void main(String[] args)
{
double TIME; double PACE;
System.out.println("This program calculates your pace given a time
and distance traveled.");
TIME = 35.5; /* 35 minutes and 30 seconds */
PACE = TIME / distance;
System.out.println("Your pace is " + PACE + " miles per hour.");
}
public static final double distance = 6.21;
}
9. A simple rule to estimate your ideal body weight is to allow 110 pounds for the
first 5 feet of height and 5 pounds for each additional inch. Write a program with
a variable for the height of a person in feet and another variable for the additional
inches. Assume the person is at least 5 feet tall. For example, a person that is 6 feet
and 3 inches tall would be represented with a variable that stores the number 6
and another variable that stores the number 3. Based on these values, calculate and
output the ideal body weight.
Search WWH ::




Custom Search