英雄无敌6 聚合服务器:java:请帮个javaBean的忙,必加100分

来源:百度文库 编辑:高校问答 时间:2024/05/05 08:03:39
学了一些java的基础知识,但是对javaBean不了解,请帮我写个:求任意两个整数的和,与求这两个整数的积的java组件,若能加一些注释说明,那更好.并用其它函数实现调用这个组件实现求和与求积的功能.谢谢.

public class test{
private String first;
private String second;
private double result;
private String opertator;
public void setFirst(String first){
this.first=first;
}
public void setSecond(String second){
this.second=second;
}
public void setOperator(String operator){
this.operator=operator;
}
public String getFirst(){
return this.first;
}
public String getSecond(){
return this.second;
}
public String getOperator(){
return this.operator;
}
public double getResult(){
return this.result;
}
public void calculte(){
double one=Double.parseDouble(first);
double two=Double.parseDouble(second);
try{
if(operator.equals("+"))result=one+two;
else if(operator.equals("*"))result=one*two;
}catch(Exception e){
System.out.println(e);
}

}
}

上面只是这个javabean程序!
调用用下面的方法:
<jsp:userbean id="calculator" scope="request" class="类路径">
<jsp:setProperty name=calculator" property="*"/>
</jsp:userbean>
<%
try{
calcutor.calculate();
out.println(calculator.getFirst()+calculator.getOperator()+calculator.getSecond()+"="+calculator.getResult())
}catch(Exception e)
{
out.println(e.getMessage())
}
%>