Java Reference
In-Depth Information
4. It is difficult to make a budget that spans several years, because prices are not stable.
If your company needs 200 pencils per year, you cannot simply use this year's price
as the cost of pencils two years from now. Because of inflation, the cost is likely to
be higher than it is today. Write a program to gauge the expected cost of an item in
a specified number of years. The program asks for the cost of the item, the number
of years from now that the item will be purchased, and the rate of inflation. The
program then outputs the estimated cost of the item after the specified period.
Have the user enter the inflation rate as a percentage, such as 5.6 (percent). Your
program should then convert the percent to a fraction, such as 0.056, and should
use a loop to estimate the price adjusted for inflation.
5. You have just purchased a stereo system that cost $1,000 on the following credit
plan: no down payment, an interest rate of 18% per year (and hence 1.5% per
month), and monthly payments of $50. The monthly payment of $50 is used to
pay the interest, and whatever is left is used to pay part of the remaining debt.
Hence, the first month you pay 1.5% of $1,000 in interest. That is $15 in interest.
So, the remaining $35 is deducted from your debt, which leaves you with a debt of
$965.00. The next month, you pay interest of 1.5% of $965.00, which is $14.48.
Hence, you can deduct $35.52 (which is $50 - $14.48) from the amount you owe.
Write a program that tells you how many months it will take you to pay off the
loan, as well as the total amount of interest paid over the life of the loan. Use a loop
to calculate the amount of interest and the size of the debt after each month. (Your
final program need not output the monthly amount of interest paid and remaining
debt, but you may want to write a preliminary version of the program that does out-
put these values.) Use a variable to count the number of loop iterations and hence,
the number of months until the debt is zero. You may want to use other variables as
well. The last payment may be less than $50 if the debt is small, but do not forget
the interest. If you owe $50, your monthly payment of $50 will not pay off your
debt, although it will come close. One month's interest on $50 is only 75 cents.
6. The Fibonacci numbers F n are defined as follows: F 0 is 1, F 1 is 1, and
F i +2 = F i + F i+1
=
i
0, 1, 2, . . . . In other words, each number is the sum of the previous two num-
bers. The first few Fibonacci numbers are 1, 1, 2, 3, 5, and 8. One place where these
numbers occur is as certain population growth rates. If a population has no deaths,
then the series shows the size of the population after each time period. It takes an
organism two time periods to mature to reproducing age, and then the organism
reproduces once every time period. The formula applies most straightforwardly to
asexual reproduction at a rate of one offspring per time period. In any event, the
green crud population grows at this rate and has a time period of five days. Hence, if
a green crud population starts out as 10 pounds of crud, then in 5 days, there is still
10 pounds of crud; in 10 days, there is 20 pounds of crud; in 15 days, 30 pounds;
in 20 days, 50 pounds; and so forth. Write a program that takes both the initial size
of a green crud population (in pounds) and a number of days as input and outputs
the number of pounds of green crud after that many days. Assume that the popula-
tion size is the same for four days and then increases every fifth day. Your program
should allow the user to repeat this calculation as often as desired.
Search WWH ::




Custom Search