2023年试题库程序编写题_第1页
2023年试题库程序编写题_第2页
2023年试题库程序编写题_第3页
2023年试题库程序编写题_第4页
2023年试题库程序编写题_第5页
已阅读5页,还剩65页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

试题序号:601题型:程序编写题难度级别:2知识点:类和对象的创建,构造函数(4-1)分值:10所需时间:15试题关键字:试题内容:编写一个矩形类Rect,包含:两个protected属性:矩形的宽width;矩形的高height。两个构造器方法:(1)一个带有两个参数的构造器方法,用于将width和height属性初化;(2)一个不带参数的构造器,将矩形初始化为宽和高都为10。两个方法:求矩形面积的方法area()求矩形周长的方法perimeter()答案内容: classRect{ protecteddoublewidth,height; publicRect(doublewidth,doubleheight){ this.width=width; this.height=height; } publicRect(){ width=10; height=10; } publicdoublearea(){ returnwidth*height; } publicdoubleperimeter(){ return2*(width+height); }}评分细则:属性定义:3分; 构造器方法:3分;方法实现:4分;试题序号:602题型:程序编写题难度级别:3知识点:类和对象的创建,构造函数(4-1)分值:10所需时间:15试题关键字:试题内容:定义一个Person类,可以在应用程序中使用该类。成员属性:Person类的属性(变量):姓名:name,字符串类型:String;性别:sex,字符型:char;年龄:age,整型:int。3个重载的构造函数:publicPerson(Strings)//设立姓名publicPerson(Strings,charc)//调用本类的构造函数Person(Strings),设立性别publicPerson(Strings,charc,inti)//调用本类的构造函数PersonPerson(Strings,char),设立年龄一个成员方法:publicStringtoString()//获得姓名、性别和年龄运用定义的Person类,请实例化对象,输出下面结果:姓名:张三性别:男年龄:21答案内容:publicclassPerson{ Stringname; charsex; intage; publicPerson() {} publicPerson(Strings) { name=s; } publicPerson(Strings,charc) { this(s); sex=c; } publicPerson(Strings,charc,inti) { this(s,c); age=i; } publicStringtoString() { Strings="姓名:"+name+"性别:"+sex+"年龄:"+age; returns;}}评分细则:类名、类声明对的1分属性定义对的1分构造方法publicPerson(Strings)编写对的2分构造方法publicPerson(Strings,char)编写对的2分构造方法publicPerson(Strings,charc,inti)编写对的2分方法publicStringtoString()编写对的2分试题序号:603题型:程序编写题难度级别:4知识点:继承(5-4),多态(5-3)分值:10所需时间:20试题关键字:试题内容:编写一个具有继承关系的java程序,规定如下:必须有this和super的使用;必须在程序中体现出方法的重载和覆盖.答案内容:classchild{ child() { System.out.println("childdefault"); } child(inti) { this(); System.out.println("int"); } voidf() { System.out.println("f()"); }}classParentextendschild{ Parent() { super(); System.out.println("parentdefault"); } Parent(inti) { super(i); System.out.println("parentint"); } voidf() { System.out.println("parentf()"); }}publicclassFoo{ publicstaticvoidmain(String[]args) { //Parentp=newParent(); Parentp=newParent(1); p.f(); }}评分细则:其中this和super的使用各占2分,继承的实现占2分,覆盖和重载各占2分。试题序号:604题型:程序编写题难度级别:3知识点:文献的输入输出(14-2)分值:10所需时间:15试题关键字:试题内容:编写一个java程序,实现拷贝文献”test.txt”中的所有内容到”test1.txt”中.答案内容:importjava.io.*;publicclassFoo{ publicstaticvoidmain(String[]args) { try { Strings=null; FileReaderfr=newFileReader("test.txt"); BufferedReaderbr=newBufferedReader(fr); FileWriterfw=newFileWriter("test1.txt"); BufferedWriterbw=newBufferedWriter(fw); while((s=br.readLine())!=null) { bw.write(s); bw.flush(); bw.newLine(); } }catch(IOExceptione) { e.printStackTrace(); } }}评分细则:其中import语句占2分Try语句块的书写占2分FileReader和FileWriter的构造各占1分复制语句的完毕占3分close语句的书写占1分试题序号:605题型:程序编写题难度级别:5知识点:抽象类,接口(5-5)分值:10所需时间:20试题关键字:试题内容:编写一个java程序,其中包含至少一个抽象类以及一个接口,再定义一个类实现抽象类以及接口中的方法.答案内容:interfaceA{ intf();}abstractclassB{ abstractintg();}publicclassFooextendsBimplementsA{ inta=2,b=1; publicintf() { return(a+b); } publicintg() { return(a*b); } publicstaticvoidmain(String[]args) { Foofoo=newFoo(); System.out.println(foo.f()); System.out.println(foo.g()); } }评分细则:接口定义对的得2分,抽象类定义对的得2分,继承抽象类并实现接口对的得2分。实现接口中的方法得2分,实现抽象类中的方法得2分试题序号:606题型:程序编写题难度级别:3知识点:基本输入输出流(14-1),while(3-2)分值:10所需时间:20试题关键字:试题内容:编写一个java程序,实现从键盘输入一个整数,输出该整数的最高位数.答案内容:importjava.io.*;publicclassFoo{ publicstaticvoidmain(String[]args) { try { InputStreamReaderisr=newInputStreamReader(System.in); BufferedReaderbr=newBufferedReader(isr); Strings=br.readLine(); inti=Integer.parseInt(s); while(i>10) { intj=i%10; i=i/10; } System.out.println(i); }catch(IOExceptione) { e.printStackTrace(); } }}评分细则:import语句占2分,try语句块占2分,从标准输入中读取整数代码段的实现占4分,计算占2分。试题序号:607题型:程序编写题难度级别:3知识点:java程序的运营环节(1-4)分值:10所需时间:16试题关键字:试题内容:分别用javaapplication和javaapplet两种方式打印出”helloworld”;答案内容:publicclassFoo{ publicstaticvoidmain(String[]args) { System.out.println("helloworld"); }}importjava.applet.Applet;importjava.awt.*;publicclassFooextendsApplet{ publicvoidpaint(Graphicsg) { g.drawString("helloworld",50,50); }}评分细则:其中application和Applet各占5分。在application中,类的定义对的占2分,main函数定义对的占2分,打印语句占1分。在applet中,import语句占1分,applet类的构造占2分,paint方法的书写占2分。试题序号:608题型:程序编写题难度级别:4知识点:java程序的运营环节(1-4)分值:10所需时间:20试题关键字:试题内容:分别用application和Applet的方式写出打印HelloWorld的代码。并针对不同的方式书写相应的运营命令。答案内容:PublicclassTest{ Publicstaticvoidmain(String[]args){ System.out.prinln(“Helloworld”);}}JavacTest.javaJavaTestimportjava.applet.Applet;publicclassTestextendsApplet{ Publicvoidpaint(Graphicsg){ g.drawString(“Helloworld”,20,20);}}//<appletcode=Test.classweight=300height=300></applet>javacTest.javaappletviewerTest.java评分细则:其中application和applet各占5分,在application中,代码的书写对的占3分,javac命令的书写对的占1分,java命令的书写对的占1分。在applet中,代码的书写占2分,html标签的书写占1分,javac命令的书写占1分,appletviewer的书写占1分。试题序号:609题型:程序编写题难度级别:3知识点:类和对象(4-1)分值:10所需时间:15试题关键字:试题内容:写出一个Point(点)类,该类具有x,y(表达点的横、纵坐标)两个属性,并定义两个个构造方法,一个无参数,将x,y均设立为0,另一对坐标值为参数,设立x,y为给定坐标值。该类的show方法输出该点的坐标值。答案内容:classPoint{intx,y;Point(){x=0;y=0;}Point(intx,inty){this.x=x;this.y=y;}publicvoidShow(){System.out.print("坐标为:("+x+","+y+”)”);}}评分细则:类的定义得1分,不带参数的构造函数的定义占3分,带参数的构造函数的定义占3分,show方法的书写占3分试题序号:610题型:程序编写题难度级别:4知识点:类和对象,构造函数(4-1)分值:10所需时间:20试题关键字:试题内容:设计并测试一个计算机类,它涉及如下内容:该计算机包含属性:品牌,颜色,cpu型号,硬盘价格以及方法:打开,关闭为该计算机类书写一个不带参数的构造函数为计算机重载一个带参数的构造函数。答案内容:publicclassComputer{ Stringname; Stringcolor; Stringcpu; intprice; publicvoidopen() { //....... } publicvoidclose() { //......... } publicComputer() { //....... } publicComputer(intname) {// ........ }}评分细则:类的定义占2分,数据成员的书写占2分,成员方法的书写占2分,两个构造函数各占2分。试题序号:611题型:程序编写题难度级别:4知识点:接口(5-5)分值:10所需时间:20试题关键字:试题内容:定义一个接口Volume,其中包含一个计算机体积的抽象方法calculateVomume,然后设计cricle和Rectangle两个类都实现接口中的这个方法。分别结算球体和长方形得体积。答案内容:interfaceVolume{ floatcalculateVolume();}classCircleimplementsVolume{ privatefloatx; privatefloaty; privatefloatradius; Circle(floatx,floaty,floatradius) { this.x=x; this.y=y; this.radius=radius; } publicfloatcalculateVolume() { return((float)Math.PI*radius*radius*radius*4/3) }}classRectangleimplementsVolume{ privatefloatlength; privatefloatwidth; privatefloatheight; Circle(floatlength,floatwidth,floatheight) { this.length=length; this.width=width; this.height=height; } publicfloatcalculateVolume() { return(length*width*height); }}评分细则:接口的定义2分,两个类的定义各占2分,方法的实现各占2分试题序号:612题型:程序编写题难度级别:4知识点:类和对象,构造函数(4-1)分值:10所需时间:20试题关键字:试题内容:编写一个类实现银行账户(bankaccount)的概念。1.银行账户的属性有“账号”、“储户姓名”、“储户身份证号”、“日期”、“金额”、“存款余额"、“累计余额"。银行账户的方法有“存款”、“取款"、等。2.编写一个带有默认构造函数(也就是没有任何参数)的类,在其中显示一些信息,然后为此类产生一些对象。3.使用刚才定义的类创建几个实例,然后通过实例来访问其中的变量和方法来完毕一定的功能。答案内容:importjava.util.*;jclassAccount{ finalintMax=5;//操作的次数 privateinttop;//储户账目管理的指针 privateintAc_id;//账号privateStringAc_name;//储户姓名privatelongAc_card;//储户身份证号privateStringAc_date[]=newString[Max];//日期tprivateintAc_money[]=newint[Max];//金额privateintAcrest[]=newint[Max];//余额privatestaticintAc_sum=0;//累计余额publicAccount()//构造函数,设立各参数{top=0; //储户账目管理的指针Ac_id=0;//账号Ac_name=“”;//储户姓名Ac_card=0;//储户身份证号}voidAc_in(StringAc_name,StringaAc_date,intaAc_money)//存款方法{Ac_date[top[=aAc_date;Ac_money[top]=aAc_money;Ac_sum=Ac_sum+aAc_money;Ac_rest[top]=Ac_sum;System.out.println(“储户姓名”+Ac_name+“日期”+Ac_date[top]+“存入”+Ac_money[top]+“存款余额”+Ac_rest[top]);. top++;}voidAc_out(StringAc_name,StringaAc_date,intaAc_money)//定义存款的方//法{Ac_date[top]=aAc_date;Ac_money[top]=-aAc_money;Ac_sum=Ac_sum-aAc_money;.Ac_rest[top]=Ac_sum;System.out.println(”储户姓名”+Ac_name+“日期”+Ac_date[top]+“取出”+(-Ac_money[top])+“存款余额”+Ac_rest[top]);top++;}}puDllcclassBankAccount{publicstaticvoidmain(String[】args) { //运用实例,调用储蓄用户Accountzhang=newAccount();zhang.Ac_in(“张梁”,“2023.6.6”,3000);zhang.Ac_out(“张梁”,“2023.6.8”,2023),zhang.Ac_in(“张梁”,“2023.7.7",3000);zhang.Ac_out(“张梁",“2023.7.9”,1500); }}评分细则:其中类的定义1分,变量定义1分,2个方法定义各占2分。构造方法占2分,对方法的调用占2分。试题序号:613题型:程序编写题难度级别:3知识点:继承(5-4)分值:10所需时间:20试题关键字:试题内容:编写一个Java应用程序,设计一个运送工具类Trartspoft,包含的成员属性有:速度、载重量;汽车类Vehicle是Transpoft的子类,其中包含的属性有:车轮个数和车重;飞机Airplane类是Transport的子类其中包含的属性有:机型和发动机数量,每个类都有相关数据的输出方法。运送工具Transport是超类,Vehicle类和Airplane类是它的子类。在设计时将公共的属性和方法放在超类Transport中。答案内容:classTransport{intpace;//速度floatload;//载重量Transport(intapace,floataload){ pace=apace; load=aload;voidshow(){System.out.println(“速度”+pace+“公里/小时”);System.out.println(“载重量”+load+“Kkg”);}}}classVehicleextendsTransport//定义汽车类{intwheels;//车轮数floatweight;//车重量Vehicle(intapace,floataload,intawheels,floataweight)//汽车类的构造函数{super(apace,aload);wheels=awheels;weight=aweight,}voidshow()//显示属性{System.out.println(“交通工具:汽车”),super.show();//调用父类的显示方法System.out.println(“车轮”+wheels+“个”);System.out.println(“重量”+weight+“kg”);System.out.println();}}classAirplaneextendsTransport//定义飞机Airplane类,飞机是Transport的子类,其中包含属性发动机类型和发动机数量Stringenginertype;//发动机类型intenginers;//发动机数量Airplane(intapace,floataload,Stringaenginertype,intaenginers){super(apace,aload);enginertype=aenginertype();enginers=aenginers;}voidshow() //显示属性{System.out.println(“交通工具:飞机”);super.show();//调用父类的显示方法System.out.println(“飞机类型”+enginertype);System.out.println(“发动机数量”+enginers);}}评分细则:第一个类的定义占1分,下面2个类的定义各占2分。3个类中的变量定义各占1分。用来数据输出的方法占2分试题序号:614题型:程序编写题难度级别:4知识点:重载(5-3)分值:10所需时间:20试题关键字:试题内容:撰写某个class,令它拥有一个重载了三次的函数。为它派生一个新得class,并为上述函数加入一份新的重载定义。证明这4个函数在派生类中都可用。答案内容:classThreeOverloads{publicvoidf(inti){System.out.println("f(inti)");}publicvoidf(charc){System.out.println("f(charc)");}}classMoreOverloadsextendsThreeOverloads{publicvoidf(Strings){System.out.println("f(Strings)");}}publicclassE13_InheritedOverloading{publicstaticvoidmain(Stringargs[]){MoreOverloadsmo=newMoreOverloads();mo.f(1);mo.f('c');mo.f("Hello");}}评分细则:父类的定义占1分。两个个重载的函数各占2分。子类的定义占1分,子类的新的重载函数占2分,在类中证明这些方法都可以用的语句占2分。试题序号:615题型:程序编写题难度级别:4知识点:包(5-5),访问控制修饰符(5-2)分值:10所需时间:20试题关键字:试题内容:撰写位于某个package内的某个类,令它具有一个protected函数。在此package之外,试着调用该protected函数。并解释其结果。答案内容:tect.*;classDerivedextendsClassWithProtected{publicvoidg(){f();//在子类中可以访问}}publicclassE15_Protected{publicstaticvoidmain(Stringargs[]){//!ClassWithProtected().f();//不能访问newDerived().g();}}///:~//:c06:protect:ClassWithPtect;publicclassClassWithProtected{protectedvoidf(){System.out.println("ProtectedMethod");}}评分细则:程序必须定义三个类。其中有两个类在一个包中,剩下一个类在一个包中。包和类的定义共占5分。对protected函数的访问以及解释占5分试题序号:616题型:程序编写题难度级别:4知识点:覆盖(5-3),继承(5-4)分值:10所需时间:20试题关键字:试题内容:撰写一个baseclass。具有两个函数,并在第一个函数中调用第二个函数。然后,派生一个新的类,并于其中覆盖第二个函数。现在产生一个派生类对象,并将它向上转型到baseclass。并调用第一个函数。最后写出输出结果并对结果进行解释。答案内容:classTwoMethods{publicvoidm1(){System.out.println("Insidem1,callingm2");m2();}publicvoidm2(){System.out.println("Insidem2");}}classInheritedextendsTwoMethods{publicvoidm2(){System.out.println("InsideInherited.m2");}}publicclassE12_MethodCalls{publicstaticvoidmain(Stringargs[]){TwoMethodsx=newInherited();x.m1();}}结果是:Insidem1,callingm2InsideInherited.m2由于第二个方法在子类中被覆盖。评分细则:程序的书写占7分,结果占2分,解释占1分。其中程序的书写中函数的覆盖占4分。其他占3分试题序号:617题型:程序编写题难度级别:4知识点:接口(5-5)分值:10所需时间:20试题关键字:试题内容:撰写三个interface,每一个都有两个函数,撰写一个新得interface,继承上述三者,并新增一个函数。撰写一个class实现出那个新得interface,并继承另一个类。接下来写4个函数。各自接受上述4个interface之一作为参数。在main()方法中,为你的那个class产生对象。并将它传入上述4个函数中答案内容:interfaceInterface1{voidf1();voidg1();}interfaceInterface2{voidf2();voidg2();}interfaceInterface3{voidf3();voidg3();}interfaceMultipleextendsInterface1,Interface2,Interface3{voidh();}classConcrete{Strings;publicConcrete(Strings){this.s=s;}}classAllextendsConcreteimplementsMultiple{publicAll(){super("All");}publicvoidh(){System.out.println("All.h");}publicvoidf1(){System.out.println("All.f1");}publicvoidg1(){System.out.println("All.g1");}publicvoidf2(){System.out.println("All.f2");}publicvoidg2(){System.out.println("All.g2");}publicvoidf3(){System.out.println("All.f3");}publicvoidg3(){System.out.println("All.g3");}}publicclassE05_InterfaceInheritance{publicvoidtakes1(Interface1i){i.f1();i.g1();}publicvoidtakes2(Interface2i){i.f2();i.g2();}publicvoidtakes3(Interface3i){i.f3();i.g3();}publicvoidtakesAll(Alla){a.f1();a.g1();a.f2();a.g2();a.f3();a.g3();a.h();}publicstaticvoidmain(Stringargs[]){E05_InterfaceInheritanceii=newE05_InterfaceInheritance();Alla=newAll();ii.takes1(a);ii.takes2(a);ii.takes3(a);ii.takesAll(a);}}///:~评分细则:前面三个interface每个1分,第四个interface2分。类的定义1分,函数的实现共2分,接受接口作为参数的四个函数共占2分试题序号:618题型:程序编写题难度级别:4知识点:异常捕获语句(12-2)分值:10所需时间:20试题关键字:试题内容:撰写一个内含main()方法得class,main()在try语句块内抛出一个Exception。请提供一个String参数给Exception构造函数。然后在catch字句中捕获异常。并打印该String参数。加入finally语句。并在其中打印出消息,证明这里的确一定会被执行答案内容:publicclassSimpleException{publicstaticvoidmain(Stringargs[]){try{thrownewException("Anexceptioninmain");}catch(Exceptione){System.out.println("e.getMessage()="+e.getMessage());}finally{System.out.println("Infinallyclause");}}}评分细则:类的定义占1分,try.catch.finally语句块占4分,Exception构造函数的定义占3分,String参数的捕获占2分试题序号:619题型:程序编写题难度级别:4知识点:异常捕获语句(12-2)分值:10所需时间:20试题关键字:试题内容:撰写一个class,内含f()和g(),请在g()中抛出自己定义的异常类型。在f()中调用g()。并捕获其异常。接着在catch子句中抛出一个异常(自己定义的另一个异常)。请在main()方法中测试你的程序代码答案内容:classAnExceptionextendsException{}classAnotherExceptionextendsException{}publicclassE05_ChangeException{publicvoidg()throwsAnException{thrownewAnException();}publicvoidf()throwsAnotherException{try{g();}catch(AnExceptione){thrownewAnotherException();}}publicstaticvoidmain(Stringargs[]){E05_ChangeExceptionce=newE05_ChangeException();try{ce.f();}catch(AnotherExceptione){System.out.println("Caught"+e);}}}评分细则:异常得定义各占2分。f()函数和g()函数得撰写各自2分。main()函数2分试题序号:620题型:程序编写题难度级别:4知识点:异常(12-2)分值:10所需时间:20试题关键字:试题内容:撰写三个新的异常。撰写一个class,其中具有一个会掷出这三种异常的参数。请在main()中调用这个函数,并使用一个能同时捕获上述三个异常类型得catch子句。答案内容:classExBaseextendsException{}classEx1extendsExBase{}classEx2extendsExBase{}classEx3extendsExBase{}classThrower{voidf()throwsEx1,Ex2,Ex3{thrownewEx1();//Youaren'tforcedtothrowallthe//exceptionsinthespecification.}}publicclassE06_CatchAll{publicstaticvoidmain(Stringargs[]){Throwert=newThrower();try{t.f();}catch(ExBasee){System.out.println("caught"+e);}catch(Exceptione){}}}评分细则:每个异常的定义各占1分,函数的撰写占3分,main()函数中catch语句占4分。试题序号:621题型:程序编写题难度级别:3知识点:break,return(3-3)分值:10所需时间:15试题关键字:试题内容:撰写一个程序,令它打印出1-100,运用关键字break,让程序在打印出数字47的时候终止,然后试着改为用return办到这一点。答案内容:publicclassE05_Break47{publicstaticvoidmain(String[]args){for(inti=1;i<=100;i++){System.out.println(i);//if(i==47)break;if(i==47)return;}}}评分细则:类的定义占1分,循环的书写占3分,break的使用占3分,return的使用占3分。试题序号:622题型:程序编写题难度级别:3知识点:重载(5-3)分值:10所需时间:20试题关键字:试题内容:产生一个类Dog,具有重载的bark().此一函数应根据不同的基本数据类型进行重载。并根据被调用的版本,打印出不同类型的消息。编写main()来调用所有不同版本。答案内容:classDog{publicvoidbark(){System.out.println("Defaultbark!");}publicvoidbark(inti){System.out.println("intbark=howl");}publicvoidbark(doublef){System.out.println("floatbark=yip");}//Etc....}publicclassE06_OverloadedDog{publicstaticvoidmain(Stringargs[]){Dogdog=newDog();dog.bark();dog.bark(1);dog.bark(1.1);}}评分细则:类的定义占2分。函数的重载占5分,main()函数中对函数的调用占3分。试题序号:623题型:程序编写题难度级别:4知识点:继承(5-4)分值:10所需时间:20试题关键字:试题内容:撰写一个baseclass,令它具有一个非缺省的构造函数,再撰写一个派生类,令它同时具有不带参数的构造函数和带参数的构造函数,请再派生类的构造函数中调用baseclass的构造函数答案内容:classBaseNonDefault{publicBaseNonDefault(inti){}}classDerivedTwoConstructorsextendsBaseNonDefault{publicDerivedTwoConstructors(){super(47);}publicDerivedTwoConstructors(inti){super(i);}}publicclassE09_CallBaseConstructor{publicstaticvoidmain(Stringargs[]){newDerivedTwoConstructors();newDerivedTwoConstructors(74);}}评分细则:baseclass的定义1分,构造函数2分,派生类的定义1分,2个构造函数各占3分,试题序号:624题型:程序编写题难度级别:3知识点:类和对象(4-1)分值:10所需时间:20试题关键字:试题内容:构造一个类来描述屏幕上的一个点,该类的构成涉及点的x和y两个坐标,以及一些对点进行的操作,涉及:取得点的坐标值,对点的坐标进行赋值,编写应用程序生成该类的对象并对其进行操作。答案内容:publicclassPoint{intx,y;publicPoint(intx,inty){this.x=x;this.y=y;}publicPointgetPoint(){PointtempPoint=newPoint(x,y);returntempPoint;}publicvoidsetPoint(Pointpoint){this.x=point.x;this.y=point.y;}publicstaticvoidmain(Stringargs[]){PointPoint1=newPoint(3,4);System.out.println("Point1:"+"("+Point1.x+","+Point1.y+")");PointPoint2=Point1.getPoint();System.out.println("Point2:"+"("+Point2.x+","+Point2.y+")");PointPoint3=newPoint(5,6);Point1.setPoint(Point3);System.out.println("Point1:"+"("+Point1.x+","+Point1.y+")");}}评分细则:类的定义占2分,变量定义占2分,2个方法各占2分,对方法的使用占2分试题序号:625题型:程序编写题难度级别:4知识点:文献输入输出流(14-2)分值:10所需时间:20试题关键字:试题内容:编写一个应用程序,完毕文献的拷贝功能,文献名从命令行得到。答案内容:importjava.io.*;classFileCopy{publicstaticvoidmain(String[]args){FileInputStreamin;FileOutputStreamout;if(args.length<2){System.out.println("Usage:javacopysrcfiledestfile");System.exit(-1);}try{in=newFileInputStream(args[0]);out=newFileOutputStream(args[1]);copyFile(in,out);}catch(Exceptione){System.out.println(e);}}privatestaticvoidcopyFile(FileInputStreamin,FileOutputStreamout){intlength;bytebuf[]=newbyte[1024];try{while((length=in.read(buf,0,1024))!=-1){out.write(buf,0,length);}}catch(Exceptione){System.out.println("Error:"+e);System.exit(-1);}}}评分细则:import语句占2分,异常捕获占2分,输入流输出流的构造占2分,文献拷贝占4分。试题序号:626题型:程序编写题难度级别:3知识点:数组(6-2)分值:10所需时间:20试题关键字:试题内容:编写一个程序用选择法对数组a[]={20,10,50,40,30,70,60,80,90,100}进行由大到小的排序。答案内容:publicclassSelectSort{publicstaticvoidmain(Stringargs[]){inta[]={20,10,50,40,30,70,60,80,90,100};inttemp;for(inti=0;i<a.length-1;i++)for(intj=i+1;j<a.length;j++){if(a[i]<a[j]){temp=a[i];a[i]=a[j];a[j]=temp;}}for(intk=0;k<a.length;k++){System.out.println("a["+k+"]:"+a[k]);}}}评分细则:类的定义占2分,算法占3分,显示结果占3分试题序号:627题型:程序编写题难度级别:4知识点:基于socket的网络通信(15-2)分值:10所需时间:25试题关键字:试题内容:使用socket编写一个服务器端程序,服务器端程序在端口8888监听,假如它接到客户端发来的"hello"请求时会回应一个"hello",对客户端的其他请求不响应。答案内容:importjava.io.*;.*;publicclassHelloServer{publicstaticvoidmain(Stringargs[])throwsIOException{ServerSocketserver=null;server=newServerSocket(8888);SocketClientSocket=null;ClientSocket=server.accept();Stringline;BufferedReaderis=newBufferedReader(newInputStreamReader(ClientSocket.getInputStream()));PrintWriteros=newPrintWriter(ClientSocket.getOutputStream());while(true){line=is.readLine();if(line.equals("hello")){os.println("hello");os.flush();}}}}评分细则:import语句占2分,socket的构造占2分,输入输出流的构造各占1分,接受消息处代码占4分试题序号:628题型:程序编写题难度级别:4知识点:线程实现技术(13-1)分值:10所需时间:20试题关键字:试题内容:编写一个应用程序,创建三个线程分别显示各自的时间。答案内容:importjava.util.*;importjava.text.*;classThreeTimeThreadextendsThread{publicThreeTimeThread(Stringstr){super(str);}publicvoidrun(){while(true){SimpleDateFormatformatter=newSimpleDateFormat("yyyy.MM.ddG'at'hh:mm:ssz");DatecurrentTime=newDate(); try{sleep(1000);}catch(Exceptione){}StringdateString=formatter.format(currentTime);System.out.println(getName()+":"+dateString);}}publicstaticvoidmain(Stringargs[])throwsException{newThreeTimeThread("first").start();newThreeTimeThread("second").start();newThreeTimeThread("third").start();}}评分细则:类的定义占2分,构造函数的书写占2分,时间的产生占3分,三个线程的启动占3分。试题序号:629题型:程序编写题难度级别:3知识点:类和对象(4-1)分值:10所需时间:20试题关键字:试题内容:给定圆柱体底面的半径和高度,计算圆柱体的体积。运用面向对象方法的形式实现答案内容:importjava.util.*;publicclassCylinder{ privatefloatr; privatefloath; privatedoublevol; Cylinder(floatr,floath) { this.r=r; this.h=h; } publicdoublevolume() { vol=Math.PI*r*r*h; returnvol; }publicstaticvoidmain(String[]args){ Cylinderc=newCylinder(12.3f,23.4f); System.out.println(c.volume());}}评分细则:import语句占1分,类的定义2分,成员变量的定义2分,方法的实现2分,对象的产生3分。试题序号:630题型:程序编写题难度级别:4知识点:继承(5-4)分值:10所需时间:20试题关键字:试题内容:设计一个学生类,其属性有姓名name,age和degree(学位),由学生类派生出本科生类,本科生添加属性specialty(专业)。.每个类都有相关数据的输出方法。答案内容:classstudent{ Stringname; intage; Stringdegree; Student(Stringname,intage,Stringdegree) { =name; this.age=age; this.degree=degree; } voidshow() { System.out.println("姓名="+name); System.out.println("年龄="+age); System.out.println("学位="+degree); }}calssundergraduateextendsstudent{ Stringspecialty; undergraduate(Stringname,intage,Stringdegree,Stringspecialty) { super(name,age,degree); this.specialty=specialty; } publicvoidshow() { super.show(); System.out.println("专业="+specialty); } }评分细则:父类的定义1分,成员变量的定义2分,方法2分。子类的定义1分,成员变量1分,方法占3分。试题序号:631题型:程序编写题难度级别:3知识点:继承(5-4)分值:10所需时间:20试题关键字:试题内容:编写一个程序是先子类对父类构造方法的调用(定义一个Father类(父类)和son类(子类),在son类中使用super关键字调用父类的构造方法)答案内容:classFather{ privateintx,y; Father(intx,inty) { this.x=x; this.y=y; } publicStringtoString() { return"x="+x+"y="+y; }}publicsonextendsFather{ privatedoubleall; son() { super(3,12); } publicvoidstaticvoidmain(String[]args) { sons=newson(); System.out.println(son.toString()); }}评分细则:父类的定义1分,构造方法书写对的3分,成员方法1分,子类定义1分,构造方法书写3分,对象的创建1分。试题序号:632题型:程序编写题难度级别:3知识点:接口(5-5)分值:10所需时间:10试题关键字:试题内容:定义一个接口Area,其中包含一个计算面积的抽象方法,calculateArea(),然后设计Circle和Rectan两个类实现这个接口中的方法calculateArea()。分别计算圆和矩形的面积。答案内容:interfaceArea{ floatcalculateArea();}classCircleimplementsArea{ floatradius; circle(floatr) { this.radius=r; } publicfloatcalculateArea() { return(float)Math.PI*radius*radius; }}classRectanimplementsArea{ floatwidth; floatheight; Rectan(floatwidth,floatheight) { this.width=width; this.height=height; } publicfloatclaculateArea() { return(float)width*height; }}publicclasstest{ publicstaticvoidmain(String[]args) { Circlec=newCircle(5); Rectanr=newRectan(12,6); }}评分细则:接口占2分。2个类每个类的定义占1分,方法的实现占2分。对象的创建各占1分。试题序号:633题型:程序编写题难度级别:4知识点:接口(5-5)分值:10所需时间:20试题关键字:试题内容:运用接口继承完毕对Biology(生物),Animal(动物),Man(人)三个接口的定义,其中Biology接口定义一个Breath方法,Animal接口定义了sex方法和ate方法,Man接口定义了think方法和study方法,定义一个NormalMan类继承上述三个接口种定义的抽象方法。答案内容:interfaceBiology{ abstractvoidbreath();}interfaceAnimalextendsBiology{ abstractvoidsex(); abstractvoidate();}interfaceManextendsAnimal{ abstractvoidthink(); abstractvoidstudy();}classNormalManimplementsBiology,Animal,Man{ privateStringname; Normal(Stringname) { =name; } publicvoidbreath() { System.out.println("breath"); } publicvoidsex() { System.out.println("sex"); } publicvoidate() { System.out.println("ate"); } publicvoidthink() { System.out.println("think"); publicvoidstudy() { System.out.println("study"); } }}评分细则:三个接口每个接口占2分,NormalMan的定义占1分,方法的实现占3分。试题序号:634题型:程序编写题难度级别:4知识点:包(5-5)分值:10所需时间:20试题关键字:试题内容:编写一个程序来实现包的定义和包的引用和使用答案内容:packagetest;publicclassMyClass{ protectedstaticfinalintm=10; protectedstaticfinalintn=10; publicintsum() { returnm+n; }}packagetest1;publicclassMyClass1{ protectedintx=10; protectedinty=10; publicintmulti() { returnx*y; }}importtest.MyClass;importtest1.MyClass1;classPlay{ publicstaticvoidmain(String[]args) { MyClassmc=newMyClass(); System.out.println(mc.sum()); MyClass1mc1=newMyClass1(); System.out.println(mc1.multi()); }}评分细则:包的定义占2分,类的定义占2分,包的引用占2分,对象的创建以及使用占4分。试题序号:635题型:程序编写题难度级别:4知识点:基本输入输出流(14-1)分值:10所需时间:20试题关键字:试题内容:设计一个程序,其功能是从命令行输入整数字符串,再将该整数字符串转换成整数。输入的数据也许具有以下格式:1234512345123xy45对这种异常进行捕获和解决答案内容:importjava.io.*;publicclassUserException{ publicstaticvoidmain(String[]args) { System.out.println("请输入一个整数字符串"); try { BufferedReaderbr=newBufferedreader(newInputStreamReader(System.in)); inta=Integer.parseInt(br.readLine(0); System.out.println("你输入的整数是:"+a); }catch(IOExceptione) { System.out.println("io错误"); }catch(NumberFormatExceptionex) { System.out.println("你输入的不是一个整数字符串"); } }}评分细则:import语句占1分,类的定义占1分,try语句块的对的书写占2分,至少应当具有ioexception和NumberFormatException,这2个异常各占2分,从命令行输入整数的代码占2分。试题序号:636题型:程序编写题难度级别:4知识点:异常(12-2)分值:10所需时间:20试题关键字:试题内容:设计方法booleanprime(intn),用来判断n是否为素数,若为素数,返回true;若不是素数,则返回false,若n<0,则抛出ArgumentOutOfException异常(自定义)答案内容:classArgumentOutOfExceptionextendsException{}classExcepTest{ publicstaticbooleanprime(intn)throwsArgumentOutOfException { if(n<0) { ArgumentOutOfExceptionae=newArgumentOutOfException(); throwae; }else { booleanisprime=true; for(inti=2;i<m;i++) { if(m%i==0) { isprime=false; break; } returnisprime; } } } publicstaticvoidmain(String[]args) { if(args.length!=1) { System.out.println("输入格式错误"); System.exit(0); } inti=Integer.parseInt(args[0]); try{ booleanresult=prime(i); System.out.println("你所输入的数是否为素数的判断结果是"+result); }catch(ArgumentOutOfExceptionae) { System.out.print("你所输入的数小于零"); } }}评分细则:自定义异常占2分,prime函数中对n<0的异常解决占3分,素数的判断占3分,main方法中的素数判断占2分试题序号:637题型:程序编写题难度级别:4知识点:文献输入输出流(14-2)分值:10所需时间:20试题关键字:试题内容:编写一个程序,分别记录并输出文本文献file.txt中元音字母a,e,i,o,u的个数答案内容:importjava.io.*;publicclassstatvowel{ publicstaticvoidmain(String[]args) { intnuma=0,nume=0,numi=0,numo=0,numu=0; intch; try { FileInputStreamfin=newFileInputStream(newFile("file.txt")); ch=fin.read(); while(ch!=-1) { charc=(char)ch; switch(c) {

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论