visual basic barcode program The Art of Java in Java

Creation PDF-417 2d barcode in Java The Art of Java

The Art of Java
PDF-417 2d Barcode Scanner In Java
Using Barcode Control SDK for Java Control to generate, create, read, scan barcode image in Java applications.
PDF417 Maker In Java
Using Barcode generator for Java Control to generate, create PDF 417 image in Java applications.
rateText.addActionListener(this); doIt.addActionListener(this);
PDF-417 2d Barcode Scanner In Java
Using Barcode recognizer for Java Control to read, scan read, scan image in Java applications.
Encode Bar Code In Java
Using Barcode maker for Java Control to generate, create barcode image in Java applications.
Finally, the number format is set to two decimal digits:
Bar Code Scanner In Java
Using Barcode scanner for Java Control to read, scan read, scan image in Java applications.
PDF417 Maker In Visual C#
Using Barcode printer for VS .NET Control to generate, create PDF417 image in Visual Studio .NET applications.
nf = NumberFormat.getInstance(); nf.setMinimumFractionDigits(2); nf.setMaximumFractionDigits(2);
Create PDF417 In .NET Framework
Using Barcode creation for ASP.NET Control to generate, create PDF 417 image in ASP.NET applications.
PDF 417 Printer In VS .NET
Using Barcode generator for Visual Studio .NET Control to generate, create PDF-417 2d barcode image in .NET applications.
The actionPerformed( ) Method
Create PDF 417 In Visual Basic .NET
Using Barcode drawer for .NET framework Control to generate, create PDF 417 image in VS .NET applications.
EAN-13 Printer In Java
Using Barcode drawer for Java Control to generate, create UPC - 13 image in Java applications.
The actionPerformed( ) method is called whenever the user presses ENTER when in a text field or presses the Compute button. This method simply calls repaint( ), which eventually causes paint( ) to be called.
Creating Barcode In Java
Using Barcode generator for Java Control to generate, create bar code image in Java applications.
ECC200 Creator In Java
Using Barcode printer for Java Control to generate, create Data Matrix image in Java applications.
The paint( ) Method
UPC E Drawer In Java
Using Barcode drawer for Java Control to generate, create UPC E image in Java applications.
Creating Barcode In Java
Using Barcode drawer for BIRT Control to generate, create barcode image in Eclipse BIRT applications.
The paint( ) method performs three main functions: it obtains the loan information entered by the user, it calls compute( ) to find the loan payments, and it displays the result. Let s now examine paint( ) line by line. After declaring the result variable, paint( ) begins by obtaining the strings from the three user-input text fields using the following sequence:
Reading Code 128 Code Set A In Visual Studio .NET
Using Barcode decoder for .NET framework Control to read, scan read, scan image in .NET framework applications.
UPC-A Supplement 2 Generator In None
Using Barcode generation for Font Control to generate, create UPC-A Supplement 5 image in Font applications.
String amountStr = amountText.getText(); String periodStr = periodText.getText(); String rateStr = rateText.getText();
Make Barcode In None
Using Barcode creation for Microsoft Excel Control to generate, create barcode image in Excel applications.
Bar Code Scanner In Java
Using Barcode Control SDK for Java Control to generate, create, read, scan barcode image in Java applications.
Next, it begins a try block and then verifies that all three fields actually contain information, as shown here:
GTIN - 128 Creator In None
Using Barcode printer for Word Control to generate, create EAN128 image in Office Word applications.
Generate EAN-13 In VB.NET
Using Barcode generator for VS .NET Control to generate, create UPC - 13 image in .NET framework applications.
try { if(amountStr.length() != 0 && periodStr.length() != 0 && rateStr.length() != 0) {
Recall that the user must enter the original loan amount, the number of years for the loan, and the interest rate. If all three text fields contain information, then the length of each string will be greater than zero. If the user has entered all the loan data, then the numeric values corresponding to those strings are obtained and stored in the appropriate instance variable. Next, compute( ) is called to compute the loan payment, and the result is displayed in the read-only text field referred to by paymentText, as shown here:
principal = Double.parseDouble(amountStr); numYears = Double.parseDouble(periodStr); intRate = Double.parseDouble(rateStr) / 100;
9: Financial Applets and Servlets
result = compute(); paymentText.setText(nf.format(result));
If the user has entered a nonnumeric value into one of the text fields, then Double.parseDouble( ) will throw a NumberFormatException. If this happens, an error message will be displayed on the status line and the Payment text field will be emptied, as shown here:
showStatus(""); // erase any previous error message } catch (NumberFormatException exc) { showStatus("Invalid Data"); paymentText.setText(""); }
Otherwise, any previously reported error is removed.
The compute( ) Method
The calculation of the loan payment takes place in compute( ). It implements the formula shown earlier and operates on the values in principal, intRate, numYears, and payPerYear. It returns the result.
NOTE
The basic skeleton used by RegPay is used by all the applets shown in this chapter.
Finding the Future Value of an Investment
Another popular financial calculation finds the future value of an investment given the initial investment, the rate of return, the number of compounding periods per year, and the number of years the investment is held. For example, you might want to know what your retirement account will be worth in 12 years if it currently contains $98,000 and has an average annual rate of return of 6 percent. The FutVal applet developed here will supply the answer. To compute the future value, use the following formula: Future Value = principal * ((rateOfRet / compPerYear) + 1)
compPerYear * numYears
where rateOfRet specifies the rate of return, principal contains the initial value of the investment, compPerYear specifies the number of compounding periods per year, and numYears specifies the length of the investment in years. If you use an annualized rate of return for rateOfRet, then the number of compounding periods is 1. The following applet called FutVal uses the preceding formula to compute the future value of an investment. The applet produced by this program is shown in Figure 9-2.
The Art of Java
Figure 9-2
The FutVal applet
Aside from the computational differences within the compute( ) method, the applet is similar in operation to the RegPay applet described in the preceding section.
// Compute the future value of an investment. import java.awt.*; import java.awt.event.*; import java.applet.*; import java.text.*; /* <applet code="FutVal" width=340 height=240> </applet> */ public class FutVal extends Applet implements ActionListener { TextField amountText, futvalText, periodText, rateText, compText; Button doIt; double principal; double rateOfRet; double numYears; int compPerYear; NumberFormat nf; public void init() { // // // // original principal rate of return length of investment in years number of compoundings per year
Copyright © OnBarcode.com . All rights reserved.