Java Reference
In-Depth Information
Sections 2.13-2.17
*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%): 1000 3.5
The interest is 2.91667
*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
=
monthlyInterestRate) numberOfYears*12
investmentAmount
*
(1
+
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: 1000.56
Enter annual interest rate in percentage: 4.25
Enter number of years: 1
Accumulated value is $1043.92
*2.22
( Financial application: monetary units ) Rewrite Listing 2.10, ComputeChange
.java, to fix the possible loss of accuracy when converting a double value to an
int value. Enter the input as an integer whose last two digits represent the cents.
For example, the input 1156 represents 11 dollars and 56 cents.
*2.23
( Cost of driving ) Write a program that prompts the user to enter the distance to
drive, the fuel efficiency of the car in miles per gallon, and the price per gallon,
and displays the cost of the trip. Here is a sample run:
Enter the driving distance: 900.5
Enter miles per gallon: 25.5
Enter price per gallon: 3.55
The cost of driving is $125.36
 
 
Search WWH ::




Custom Search