19.09.2015 Views

Prentice.Hall.Introduction.to.Java.Programming,.Brief.Version.9th.(2014).[sharethefiles.com]

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

creates a bean named loan for the Loan class. Line 10<br />

<br />

associates the bean properties loanAmount, annualInteresteRate, and<br />

numberOfYears with the input parameter values and performs type<br />

conversion au<strong>to</strong>matically.<br />

Lines 11–13 use the accessor methods of the loan bean <strong>to</strong> get the loan<br />

amount, annual interest rate, and number of years.<br />

This program acts the same as in Listings 43.3 and 43.4, ComputeLoan.jsp<br />

and ComputeLoan1.jsp, but the coding is much simplified.<br />

43.9.2 Example: Computing Fac<strong>to</strong>rials Using <strong>Java</strong>Beans<br />

This example creates a <strong>Java</strong>Beans <strong>com</strong>ponent named Fac<strong>to</strong>rialBean and uses<br />

it <strong>to</strong> <strong>com</strong>pute the fac<strong>to</strong>rial of an input number in a JSP page named<br />

Fac<strong>to</strong>rialBean.jsp, as shown in Figure 43.8.<br />

Figure 43.8<br />

The fac<strong>to</strong>rial of an input integer is <strong>com</strong>puted using a method in<br />

Fac<strong>to</strong>rialBean.<br />

Create a <strong>Java</strong>Beans <strong>com</strong>ponent named Fac<strong>to</strong>rialBean.java (Listing 43.9).<br />

Create Fac<strong>to</strong>rialBean.jsp (Listing 43.10).<br />

Listing 43.9 Fac<strong>to</strong>rialBean.java<br />

<br />

<br />

<br />

package chapter43;<br />

public class Fac<strong>to</strong>rialBean {<br />

private int number;<br />

/** Return number property */<br />

public int getNumber() {<br />

return number;<br />

}<br />

/** Set number property */<br />

public void setNumber(int newValue) {<br />

number = newValue;<br />

}<br />

16

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!