Java Reference
In-Depth Information
**2.13
( Financial application: compound value ) Suppose you save $100 each month
into a savings account with the annual interest rate 5%. Thus, the monthly inter-
est rate is 0.05/12
=
0.00417. After the first month, the value in the account
becomes
100 * (1 + 0.00417) = 100.417
After the second month, the value in the account becomes
(100 + 100.417) * (1 + 0.00417) = 201.252
After the third month, the value in the account becomes
(100 + 201.252) * (1 + 0.00417) = 302.507
and so on.
Write a program that prompts the user to enter a monthly saving amount and
displays the account value after the sixth month. (In Exercise 5.30, you will use a
loop to simplify the code and display the account value for any month.)
Enter the monthly saving amount: 100
After the sixth month, the account value is $608.81
*2.14
( Health application: computing BMI ) Body Mass Index (BMI) is a measure of
health on weight. It can be calculated by taking your weight in kilograms and
dividing by the square of your height in meters. Write a program that prompts the
user to enter a weight in pounds and height in inches and displays the BMI. Note
that one pound is 0.45359237 kilograms and one inch is 0.0254 meters. Here is
a sample run:
VideoNote
Compute BMI
Enter weight in pounds: 95.5
Enter height in inches: 50
BMI is 26.8573
2.15
( Geometry: distance of two points ) Write a program that prompts the user to enter
two points (x1, y1) and (x2, y2) and dis plays their distance betw een them.
The formula for computing the distance is
x 1 ) 2
y 1 ) 2 . Note that
2
( x 2
-
+
( y 2
-
you can use Math.pow(a, 0.5) to compute
2
a . Here is a sample run:
Enter x1 and y1: 1.5 -3.4
Enter x2 and y2: 4 5
The distance between the two points is 8.764131445842194
2.16
( Geometry: area of a hexagon ) Write a program that prompts the user to enter the
side of a hexagon and displays its area. The formula for computing the area of a
hexagon is
3
2
3
s 2 ,
Area
=
2
 
Search WWH ::




Custom Search