19.09.2015 Views

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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

method fac<strong>to</strong>rialBeanId.getFac<strong>to</strong>rial() (line 25) returns the fac<strong>to</strong>rial<br />

for the number in fac<strong>to</strong>rialBeanId.<br />

DESIGN GUIDE<br />

<br />

Mixing a lot of <strong>Java</strong> code with HTML in a JSP page makes<br />

the code difficult <strong>to</strong> read and <strong>to</strong> maintain. You should<br />

move the <strong>Java</strong> code <strong>to</strong> a .java file as much as you can.<br />

***End DESIGN GUIDE<br />

Following the preceding design guide, you may improve the preceding<br />

example by moving the <strong>Java</strong> code in lines 23–25 <strong>to</strong> the Fac<strong>to</strong>rialBean<br />

class. The new Fac<strong>to</strong>rialBean.java and Fac<strong>to</strong>rialBean.jsp are given in<br />

Listings 43.11 and 43.12.<br />

Listing 43.11 NewFac<strong>to</strong>rialBean.java<br />

<br />

<br />

<br />

package chapter43;<br />

import java.text.*;<br />

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

private int number;<br />

}<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 />

/** Obtain fac<strong>to</strong>rial */<br />

public long getFac<strong>to</strong>rial() {<br />

long fac<strong>to</strong>rial = 1;<br />

for (int i = 1; i

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

Saved successfully!

Ooh no, something went wrong!