img
String payStr = paymentText.getText();
try {
if(orgPStr.length() != 0
&&
numPayStr.length() !=
0 &&
rateStr.length() != 0
&&
payStr.length() != 0)
{
orgPrincipal = Double.parseDouble(orgPStr);
numPayments = Double.parseDouble(numPayStr);
intRate = Double.parseDouble(rateStr) / 100;
payment = Double.parseDouble(payStr);
result = compute();
remBalText.setText(nf.format(result));
}
showStatus(""); // erase any previous error message
} catch (NumberFormatException exc) {
showStatus("Invalid Data");
remBalText.setText("");
}
}
// Compute the loan balance.
double compute() {
double bal = orgPrincipal;
double rate = intRate / payPerYear;
for(int i = 0; i < numPayments; i++)
bal -= payment - (bal * rate);
return bal;
}
}
Creating Financial Ser vlets
Although applets are easy to create and use, they are only one half of the Java Internet
equation. The other half is servlets. Servlets execute on the server side of the connection,
and they are more appropriate for some applications. Because many readers may want to
use servlets rather than applets in their commercial applications, the remainder of this
chapter shows how to convert the financial applets into servlets.
Because all the financial applets use the same basic skeleton, we will walk through
the conversion of only one applet: RegPay. You can then apply the same basic process to
convert any of the other applets into servlets on your own. As you will see, it's not hard to do.
NOTE  For information on creating, testing, and running servlets, see Chapter 31.
OTE
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home