package red.star;
public class Triangle {
double sideA=-1,sideB=-1,sideC=-1, area=-1;
boolean triangle;
public void setSideA(double a) {
sideA=a;
}
public double getSideA() {
return sideA;
}
public void setSideB(double b) {
sideB=b;
}
public double getSideB() {
return sideB;
}
public void setSideC(double c) {
sideC=c;
}
public double getSideC() {
return sideC;
}
public double getArea() {
double p=(sideA+sideB+sideC)/2.0;
if(triangle)
area=Math.sqrt(p*(p-sideA)*(p-sideB)*(p-sideC));
return area;
}
public boolean isTriangle()
{ if(sideA<sideB+sideC&&sideB<sideA+sideC&&sideC<sideA+sideB)
triangle=true;
else triangle=false;
return triangle;
}
}
<%@ page contentType="text/html;charset=gb2312" %>
<jsp:useBean id="tri" class="red.star.Triangle" scope="request"/>
<HTML><body bgcolor=#AAFF99><font size=3>
<form action="" method="post" >
输入三角形三边:
边A:<input type=text name="sideA" value=0 size=5>
边B:<input type=text name="sideB" value=0 size=5>
边C:<input type=text name="sideC" value=0 size=5>
<input type=submit value="提交">
</form>
<jsp:setProperty name="tri" property="*"/>
三角形的三边是:
<jsp:getProperty name="tri" property="sideA"/>,
<jsp:getProperty name="tri" property="sideB"/>,
<jsp:getProperty name="tri" property="sideC"/>.
<br><b>这三个边能构成一个三角形吗?<jsp:getProperty name="tri" property="triangle"/>
<br>面积是:<jsp:getProperty name="tri" property="area"/></b>
</font></body></HTML>
package red.star;
public class ComputerBean {
double numberOne,numberTwo,result;
String operator="+";
public void setNumberOne(double n) {
numberOne=n;
}
public double getNumberOne() {
return numberOne;
}
public void setNumberTwo(double n) {
numberTwo=n;
}
public double getNumberTwo() {
return numberTwo;
}
public void setOperator(String s) {
operator=s.trim();;
}
public String getOperator() {
return operator;
}
public double getResult() {
if(operator.equals("+"))
result=numberOne+numberTwo;
else if(operator.equals("-"))
result=numberOne-numberTwo;
else if(operator.equals("*"))
result=numberOne*numberTwo;
else if(operator.equals("/"))
result=numberOne/numberTwo;
return result;
}
}
<%@ page contentType="text/html;charset=gb2312" %>
<jsp:useBean id="computer" class="red.star.ComputerBean" scope="session"/>
<HTML><body bgcolor=yellow><font size=2>
<jsp:setProperty name="computer" property="*"/>
<form action="" method=post name=form>
<input type=text name="numberOne" size=6>
<select name="operator" >
<option value="+">+
<option value="-">-
<option value="*">*
<option value="/">/
</select>
<input type=text name="numberTwo" size=6>
<br> <input type="submit" value="提交" name="submit">
</form>
<b>
<jsp:getProperty name="computer" property="numberOne"/>
<jsp:getProperty name="computer" property="operator"/>
<jsp:getProperty name="computer" property="numberTwo"/> =
<jsp:getProperty name="computer" property="result"/> </b>
</font></body></HTML>
package red.star;
import java.io.*;
public class Play {
int imageNumber=0,max;
String pictureName[],playImage;
String webDir="";
String tomcatDir;
public Play() {
File f= new File("");
String path = f.getAbsolutePath();
int index = path.indexOf("bin");
tomcatDir = path.substring(0,index);
}
public void setWebDir(String s) {
webDir =s;
if(pictureName==null) {
File dirImage=new File(tomcatDir+"/webapps/"+webDir+"/image");
pictureName=dirImage.list();
}
if(pictureName!=null)
max=pictureName.length;
}
public void setImageNumber(int n){
if(n<0)
n=max-1;
if(n==max)
n=0;
imageNumber=n;
}
public int getImageNumber() {
return imageNumber;
}
public String getPlayImage() {
if(pictureName!=null)
playImage=pictureName[imageNumber];
return playImage;
}
}
|