欢迎来到天天文库
浏览记录
ID:61443027
大小:49.42 KB
页数:26页
时间:2021-01-31
《java程序员下午题.docx》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、2004下半年试题八(15分,每空3分)阅读以下说明和Java源程序,将应填入(n)处的字句写在答题纸的对应栏内。【说明】以下程序的功能是计算三角形、矩形和正方形的面积并输出。程序由5个类组成:AreaTest是主类,类Triangle、Rectangle和Square分别表示三角形、矩形和正方形,抽象类Figure提供了一个计算面积的抽象方法。【程序】publicclassAreaTest{publicstaticvoidmain(Stringargs[]){Figure[]figures={newTriangle(2,3,3),newRectangle(5
2、,8),newSquare(5)};for(inti=0;i3、.height=height;this.width=width;}publicStringtoString(){return"Rectangle:height="+height+",width="+width+":";}publicdoublegetArea(){return______(2)_________;}}(3)publicclassSquareextends____(3)_____publicSquare(doublewidth){____(4)____;}publicStringtoString(){return"Square:width="+w4、idth+":";}}PublicclassTriangleextends____(5)_____{doublela;doublelb;doublelc;publicTriangle(doublela,doublelb,doublelc){this.la=la;this.lb=lb;this.lc=lc;}publicStringtoString(){return"Triangle:sides="+la+","+lb+","+lc+":";}publicdoublegetArea(){doubles=(la+lb+lc)/2.0;returnMath.sqrt5、(s*(s-la)*(s-lb)*(s-lc));}}参考答案1.Figure2.height*width3.Rectangle4.super(width,width)5.Figure2005上半年试题六(15分,每空3分)阅读以下说明、Java代码和HTML文档,将应填入(n)处的字句写在答题纸的对应栏内。[说明]当用户启动html浏览器并首次打开下面的html文档时,JavaApplet小程序在显示面板上显示字符串“Welcome!”;当html页面被其它窗口遮挡后再次显示时,小程序在显示面板上显示“Welcomeback!”。[Java代码]import6、java.awt.*;importjava.applet.*;publicclassHelloAppletextends___(1)____{publicvoidpaint(___(2)____){g.drawString(message,10,20);message="welcomeback!";}publicvoid____(3)____(){message="Welcome!";}private___(4)___message;}[HTML文档]HTMLTestHelloAppletPage7、d>TestHelloApplet小程序参考答案:1.Applet2.Graphicsg3.init4.String5.HelloApplet.class2005下半年试题八(共15分)阅读以下说明和Java代码,将解答写入答题纸的对应栏内。[说明]已知类Stock和类JavaMain都定义在JavaMain.java文件中,类Stock的定义
3、.height=height;this.width=width;}publicStringtoString(){return"Rectangle:height="+height+",width="+width+":";}publicdoublegetArea(){return______(2)_________;}}(3)publicclassSquareextends____(3)_____publicSquare(doublewidth){____(4)____;}publicStringtoString(){return"Square:width="+w
4、idth+":";}}PublicclassTriangleextends____(5)_____{doublela;doublelb;doublelc;publicTriangle(doublela,doublelb,doublelc){this.la=la;this.lb=lb;this.lc=lc;}publicStringtoString(){return"Triangle:sides="+la+","+lb+","+lc+":";}publicdoublegetArea(){doubles=(la+lb+lc)/2.0;returnMath.sqrt
5、(s*(s-la)*(s-lb)*(s-lc));}}参考答案1.Figure2.height*width3.Rectangle4.super(width,width)5.Figure2005上半年试题六(15分,每空3分)阅读以下说明、Java代码和HTML文档,将应填入(n)处的字句写在答题纸的对应栏内。[说明]当用户启动html浏览器并首次打开下面的html文档时,JavaApplet小程序在显示面板上显示字符串“Welcome!”;当html页面被其它窗口遮挡后再次显示时,小程序在显示面板上显示“Welcomeback!”。[Java代码]import
6、java.awt.*;importjava.applet.*;publicclassHelloAppletextends___(1)____{publicvoidpaint(___(2)____){g.drawString(message,10,20);message="welcomeback!";}publicvoid____(3)____(){message="Welcome!";}private___(4)___message;}[HTML文档]
7、d>
8、中有四处错误,分别在代码的第01、02
此文档下载收益归作者所有