网站大量收购独家精品文档,联系QQ:2885784924

JavaBean的使用计算器.docx

  1. 1、本文档共9页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
JavaBean的使用计算器

JavaBean创建和使用——计算器1、掌握JavaBean创建和使用方法;2、领会JavaBean简化页面设计的优势等。设计简单计算器要求:完成加减乘除? ? 当除数为零时报错? ? 将加减乘除部分写在JavaBean中,在JSP页面中调用显示计算结果。Calculator.javapackage com.jk.yt;import java.math.BigDecimal;publicclass Calculator {private String onenum = 0;private String twonum = 0;privatecharfuhao = +;private String result;public String getOnenum() {returnonenum;}publicvoid setOnenum(String onenum) {this.onenum = onenum;}public String getTwonum() {returntwonum;}publicvoid setTwonum(String twonum) {this.twonum = twonum;}publicchar getFuhao() {returnfuhao;}publicvoid setFuhao(char fuhao) {this.fuhao = fuhao;}public String getResult() {returnresult;}publicvoid setResult(String result) {this.result = result;}publicvoid calculate(){BigDecimal a=new BigDecimal(this.onenum);BigDecimal b=new BigDecimal(this.twonum);switch (this.fuhao) {case+:this.result=a.add(b).toString();break;case-:this.result=a.subtract(b).toString();break;case*:this.result=a.multiply(b).toString();break;case/:if(b.doubleValue()==0){thrownew RuntimeException(h1sorry,出错了!!除数不能为零/h1);}this.result=a.divide(b,10,BigDecimal.ROUND_HALF_DOWN).toString();break;default:break;}}}index.jsp:%@pagelanguage=javacontentType=text/html; charset=UTF-8pageEncoding=UTF-8%!DOCTYPEhtmlPUBLIC-//W3C//DTD HTML 4.01 Transitional//EN/TR/html4/loose.dtdhtmlheadmetahttp-equiv=Content-Typecontent=text/html; charset=UTF-8title计算器/titlestyletype=text/css#top {text-align: center;}table {width:330px;height:220px;text-align: center;margin: 0 auto;background: url(4.jpg);}/style/headbodyjsp:useBeanid=calculateclass=com.jk.yt.Calculator/jsp:useBeanjsp:setPropertyproperty=*name=calculate/%try {calculate.calculate();%divid=toph1计算结果:jsp:getPropertyproperty=onenumname=calculate/jsp:getPropertyproperty=fuhaoname=calculate/jsp:getPropertyproperty=twonumname=calculate/=jsp:getPropertyproperty=resultname=calculate//h1hr/divformaction=index.jspmethod=postname=formtabletrtdcolspan=2h1简单的计算器/h1/td/trtrtd第一个参数/tdtdinputtype=textname=onenum//td/trtrtdcolspan=2selectnam

文档评论(0)

xcs88858 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

版权声明书
用户编号:8130065136000003

1亿VIP精品文档

相关文档