Java Reference
In-Depth Information
2.18
( Print a table ) Write a program that displays the following table:
a b pow(a, b)
1 2 1
2 3 8
3 4 81
4 5 1024
5 6 15625
2.19
( Geometry: distance of two points ) Write a program that prompts the user to enter
two points (x1, y1) and (x2, y2) and di splays their distance betw een them.
The formula for computing the distance is
x 1 ) 2
y 1 ) 2 .
2
( x 2 -
+
( y 2 -
Note that
you can use Math.pow(a, 0.5) to compute
2
a .
Here is a sample run:
Enter x1 and y1:
Enter x2 and y2:
The distance between the two points is 8.764131445842194
1.5 -3.4
4 5
Sections 2.13-2.16
*2.20
( Financial application: calculate interest ) If you know the balance and the annual
percentage interest rate, you can compute the interest on the next monthly pay-
ment using the following formula:
interest
=
balance
*
(annualInterestRate / 1200)
Write a program that reads the balance and the annual percentage interest rate and
displays the interest for the next month. Here is a sample run:
Enter balance and interest rate (e.g., 3 for 3%):
The interest is 2.91667
1000 3.5
*2.21
( Financial application: calculate future investment value ) Write a program that
reads in investment amount, annual interest rate, and number of years, and dis-
plays the future investment value using the following formula:
futureInvestmentValue =
investmentAmount x (1 + monthlyInterestRate) numberOfYears*12
For example, if you enter amount 1000 , annual interest rate 3.25% , and number of
years 1 , the future investment value is 1032.98 .
Here is a sample run:
Enter investment amount:
Enter annual interest rate in percentage:
Enter number of years:
Accumulated value is $1043.34
1000
4.25
1
 
Search WWH ::




Custom Search