A套第1页共3页学号姓名班级考试时间年月日装订线西安财经学院试题答案命题教师王庆林学期2012—2013学年第1学期使用班级电商1001-1004考核方式闭卷笔试课程名称Java程序设计阅卷教师签名题号一二三四五六七八九十总分得分注意事项:命题教师1.出题用五号字、宋体输入,打印用正规A4纸张。2.装订线以外的各项均由命题教师填写,不得漏填。考生1.装订线内的“班级”、“学号”、“姓名”、“时间”等栏由考生本人填写。2.一律用黑色的签字笔答题,否则试卷无效。第一题答案请填入下列表格中。题号123456789101112131415选项abadacadccbddba题号161718192021222324252627282930选项ccbcbcdadcaabcb第二题答案请写在下面:1.var1.a();//Kurt1/Jerry3/Kurt3((Jerry)var2).c();//运行时错误var3.b();//编译错误((Jerry)var4).a();//Kurt1/Chris3((Jerry)var4).c();//Chris3((Kurt)var5).c();//Jerry3/Kurt32.hands:863.ABB4.t1c2c15.Radiusis1.06.countis11timesis07.(2)(1)(5)(8)(4)(3)(7)(6)8.如果a程序用b中的Circle类,则执行结果为:false如果a程序用c中的Circle类,则执行结果为:true9.truefalsetrue第三题答案请写在下面:1.Octagon-side:double+Octagon()+Octagon(side:double)+getSide():double+setSide(side:double):void«interface»Colorable+howToColor():voidGeometricObject«interface»CloneablepublicclassOctagonextendsGeometricObjectimplementsComparable,Cloneable{privatedoubleside;/**ConstructaOctagonwiththespecifiedside*/publicOctagon(doubleside){//Implementitthis.side=side;}/**ImplementtheabstractmethodgetAreainGeometricObject*/publicdoublegetArea(){//Implementitreturn(2+4/Math.sqrt(2))*side*side;}/**ImplementtheabstractmethodgetPerimeterinGeometricObject*/publicdoublegetPerimeter(){//Implementitreturn8*side;}/**ImplementthecompareTomethodinA套第2页共3页学号姓名班级考试时间年月日装订线theComparableinterfaceto*/publicintcompareTo(Objectobj){//Implementit(comparetwoOctagonsbasedontheirareas)doublethisArea=this.getArea();doubleotherArea=((Octagon)obj).getArea();if(thisAreaotherArea)return1;elseif(thisArea==otherArea)return0;elsereturn-1;}/**ImplementtheclonemethodintheObjectclass*/publicObjectclone(){//Implementittry{returnsuper.clone();}catch(CloneNotSupportedExceptionex){returnnull;}}}2.importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;importjavax.swing.border.*;publicclassInvestmentextendsJFrame{privateJTextFieldjtfInvestmentAmount;//输入投资额的文本框privateJTextFieldjtfYears;//输入投资年的文本框privateJTextFieldjtfInterestRate;//输入利率的文本框privateJTextFieldjtfFutureValue;//显示未来总额的文本框privateJButtonjbtCalculate;//计算按钮publicstaticvoidmain(String[]args){JFrameframe=newInvestment();frame.pack();frame.setTitle(investmentvaluecalculator);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setLocationRelativeTo(null);//Centertheframeframe.setVisible(true);}publicInvestment(){//采用网格布局创建面板,在面板上显示标签、文本框和按钮。JPanelp=newJPanel();p.setLayout(newGridLayout(4,2,5,0));p.add(newJLabel(InvestmentAmount));p.add(jtfInvestmentAmount=newJTextField(8));p.add(newJLabel(Years));p.add(jtfYears=newJTextField(8));p.add(newJLabel(AnnualInterestRate));p.add(jtfInterestRate=newJTextField(8));p.add(newJLabel(Futurevalue));p.add(jtfFutureValue=newJTextField(8));jtfFutureValue.setEditable(false);//把面板增加到窗口框架中setLayout(newBorderLayout());add(p,BorderLayout.CENTER);//把按钮增加到窗口框架中JPanelp1=newJPanel(newFlowLayout(FlowLayout.RIGHT));p1.add(jbtCalculate=newJButton(Calculate));add(p1,BorderLayout.SOUTH);//给按钮注册动作事件的监听器jbtCalculate.addActionListener(newActionListener(){A套第3页共3页学号姓名班级考试时间年月日装订线publicvoidactionPerformed(ActionEvente){calculate();}});}//编写计算未来总额值的方法calculate,完成计算和结果值的显示publicvoidcalculate(){doubleinvestmentAmount=Double.valueOf(jtfInvestmentAmount.getText().trim()).doubleValue();intyears=Integer.valueOf(jtfYears.getText().trim()).intValue();doubleinterestRate=Double.valueOf(jtfInterestRate.getText().trim()).doubleValue();doublefutureValue=investmentAmount*Math.pow((1+interestRate/(12*100)),12*years);jtfFutureValue.setText((int)(futureValue*100)/100.0+);}}