426
12.Write the statements to declare a JPanelvariable, instantiate an object for it,
set its layout manager to FlowLayout, and add three labels to it.
Programming Problem
1.You have bought a car, taking out a loan with an annual interest rate of 9%. You
will make 36 monthly payments of $165.25 each. You want to keep track of the
remaining balance you owe after each monthly payment. The formula for the
remaining balance is
balk= pmt
where
balk= balance remaining after the kth payment
k= payment number (1, 2, 3,...)
pmt= amount of the monthly payment
i= interest rate per month (annual rate ÷ 12)
n= total number of payments to be made
Write an application to calculate and display the balance remaining after each
monthly payment. Start by showing the remaining balance after the first
payment, and show each subsequent payment when a button is clicked.
Display an identifying message with each numerical result that indicates
which payment period is being displayed. Be sure to include appropriate
comments in your code, choose meaningful identifiers, and use indentation as
we do in the code in this chapter.
Case Study Follow-Up
1.Does Rainfallcrash if the user enters nonnumeric values? Explain.
2.Write a test plan for Rainfall.
3.Rainfallstops when the user closes the window. How else could the
application be designed to allow the user to quit? Explain.
4.What happens when a negative value is input in Rainfall?
5.ModifyRainfallto display the names of three towns in your area for its stations.
6.Modify Rainfallto handle six stations, using names of towns near you.
7.ModifyRainfallto compute and display the average rainfall for a storm for
each station.
1 – (1 + i)k–n
i