JAVA程序设计5复赛B卷.docx

上传人:b****1 文档编号:2395284 上传时间:2023-05-03 格式:DOCX 页数:17 大小:25.71KB
下载 相关 举报
JAVA程序设计5复赛B卷.docx_第1页
第1页 / 共17页
JAVA程序设计5复赛B卷.docx_第2页
第2页 / 共17页
JAVA程序设计5复赛B卷.docx_第3页
第3页 / 共17页
JAVA程序设计5复赛B卷.docx_第4页
第4页 / 共17页
JAVA程序设计5复赛B卷.docx_第5页
第5页 / 共17页
JAVA程序设计5复赛B卷.docx_第6页
第6页 / 共17页
JAVA程序设计5复赛B卷.docx_第7页
第7页 / 共17页
JAVA程序设计5复赛B卷.docx_第8页
第8页 / 共17页
JAVA程序设计5复赛B卷.docx_第9页
第9页 / 共17页
JAVA程序设计5复赛B卷.docx_第10页
第10页 / 共17页
JAVA程序设计5复赛B卷.docx_第11页
第11页 / 共17页
JAVA程序设计5复赛B卷.docx_第12页
第12页 / 共17页
JAVA程序设计5复赛B卷.docx_第13页
第13页 / 共17页
JAVA程序设计5复赛B卷.docx_第14页
第14页 / 共17页
JAVA程序设计5复赛B卷.docx_第15页
第15页 / 共17页
JAVA程序设计5复赛B卷.docx_第16页
第16页 / 共17页
JAVA程序设计5复赛B卷.docx_第17页
第17页 / 共17页
亲,该文档总共17页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

JAVA程序设计5复赛B卷.docx

《JAVA程序设计5复赛B卷.docx》由会员分享,可在线阅读,更多相关《JAVA程序设计5复赛B卷.docx(17页珍藏版)》请在冰点文库上搜索。

JAVA程序设计5复赛B卷.docx

JAVA程序设计5复赛B卷

第五届全国ITAT教育工程就业技能大赛复赛试题

Java程序设计(B卷)

请考生仔细阅读并严格遵守题目中关于文件保存和命名的要求。

请务必按照试卷要求为文件命名。

考生答题完毕后,首先创建以“准考证号”命名的文件夹(形式如:

433034683),并将考试结果严格按题目上的命名要求进行命名并直接保存在该文件夹下。

注意:

考生不得在该文件夹下创建任何子文件夹,所有考试结果均直接保存在该文件夹根目录下。

  然后选中整个文件夹,用Winrar压缩工具打包后存放在本考场指定的考试结果存放地址,经监考老师确认上传无误后方可离开考场。

注意:

在提交答案时,请务必选中上述存放作品的文件夹(如前面创建的433034683文件夹,而不是文件夹下的全部文件)进行压缩,在完成答案提交后,请确保上述压缩包仍保存在本地计算机中。

请务必按照试卷要求提交指定的文件,不得包含非题目要求的过程文件和临时文件,不得包含本试题文件和试题素材。

注意:

凡违反上述规定的考生,其成绩一律按零分处理。

题目命名要求:

请将编写好的源程序以“T+题号”的方式命名,例如第1题的源程序保存为“T1.java”),题目本身有命名要求的除外。

1、设计一个Student接口,以一维数组存储一个班级的学生姓名。

该接口中有一个抽象方法getStudentName()。

设计一个类Test,该类实现接口Student中的方法getStudentName(),功能是获取学生姓名并显示。

(20分)

publicclassTest3implementsStudent{

publicstaticvoidmain(Stringarg[]){

Test3t3=newTest3();

t3.getStudentName();

}

publicvoidgetStudentName(){

for(inti=0;i

System.out.print(name[i]+"");

}

}

}

interfaceStudent{

String[]name={"张三","李四","王二","赵武","胡说","刘能"};

abstractvoidgetStudentName();

}输出结果为:

王张徐李刘莫

2、如下图所示,利用Java的GUI和多线程编程技术,编写一个时钟显示程序。

(30分)

 

importjava.util.*;

importjava.awt.*;

importjava.applet.*;

importjava.text.*;

publicclassTest6extendsAppletimplementsRunnable{

privatevolatileThreadtimer;//Thethreadthatdisplaysclock

privateintlastxs,lastys,lastxm,

lastym,lastxh,lastyh;//Dimensionsusedtodrawhands

privateSimpleDateFormatformatter;//Formatsthedatedisplayed

privateStringlastdate;//Stringtoholddatedisplayed

privateFontclockFaceFont;//Fontfornumberdisplayonclock

privateDatecurrentDate;//Usedtogetdatetodisplay

privateColorhandColor;//Colorofmainhandsanddial

privateColornumberColor;//Colorofsecondhandandnumbers

privateintxcenter=80,ycenter=55;//Centerposition

publicvoidinit(){

intx,y;

lastxs=lastys=lastxm=lastym=lastxh=lastyh=0;

formatter=newSimpleDateFormat("EEEMMMddhh:

mm:

ssyyyy",

Locale.getDefault());

currentDate=newDate();

lastdate=formatter.format(currentDate);

clockFaceFont=newFont("Serif",Font.PLAIN,14);

handColor=Color.blue;

numberColor=Color.darkGray;

//背景色

try{

setBackground(newColor(Integer.parseInt(getParameter("bgcolor"),

16)));

}catch(NullPointerExceptione){

}catch(NumberFormatExceptione){

}

//前景色

try{

handColor=newColor(Integer.parseInt(getParameter("fgcolor1"),

16));

}catch(NullPointerExceptione){

}catch(NumberFormatExceptione){

}

//字体颜色

try{

numberColor=newColor(Integer.parseInt(getParameter("fgcolor2"),

16));

}catch(NullPointerExceptione){

}catch(NumberFormatExceptione){

}

resize(300,300);//设置窗口大小

}

//Paintisthemainpartoftheprogram

publicvoidupdate(Graphicsg){

intxh,yh,xm,ym,xs,ys;

ints=0,m=10,h=10;

Stringtoday;

currentDate=newDate();

formatter.applyPattern("s");

try{

s=Integer.parseInt(formatter.format(currentDate));

}catch(NumberFormatExceptionn){

s=0;

}

formatter.applyPattern("m");

try{

m=Integer.parseInt(formatter.format(currentDate));

}catch(NumberFormatExceptionn){

m=10;

}

formatter.applyPattern("h");

try{

h=Integer.parseInt(formatter.format(currentDate));

}catch(NumberFormatExceptionn){

h=10;

}

//Setpositionoftheendsofthehands

xs=(int)(Math.cos(s*Math.PI/30-Math.PI/2)*45+xcenter);

ys=(int)(Math.sin(s*Math.PI/30-Math.PI/2)*45+ycenter);

xm=(int)(Math.cos(m*Math.PI/30-Math.PI/2)*40+xcenter);

ym=(int)(Math.sin(m*Math.PI/30-Math.PI/2)*40+ycenter);

xh=(int)(Math.cos((h*30+m/2)*Math.PI/180-Math.PI/2)*30

+xcenter);

yh=(int)(Math.sin((h*30+m/2)*Math.PI/180-Math.PI/2)*30

+ycenter);

//Getthedatetoprintatthebottom

formatter.applyPattern("EEEMMMddHH:

mm:

ssyyyy");

today=formatter.format(currentDate);

g.setFont(clockFaceFont);

//Eraseifnecessary

g.setColor(getBackground());

if(xs!

=lastxs||ys!

=lastys){

g.drawLine(xcenter,ycenter,lastxs,lastys);

g.drawString(lastdate,5,125);

}

if(xm!

=lastxm||ym!

=lastym){

g.drawLine(xcenter,ycenter-1,lastxm,lastym);

g.drawLine(xcenter-1,ycenter,lastxm,lastym);

}

if(xh!

=lastxh||yh!

=lastyh){

g.drawLine(xcenter,ycenter-1,lastxh,lastyh);

g.drawLine(xcenter-1,ycenter,lastxh,lastyh);

}

//Drawdateandhands

g.setColor(numberColor);

g.drawString(today,5,125);

g.drawLine(xcenter,ycenter,xs,ys);

g.setColor(handColor);

g.drawLine(xcenter,ycenter-1,xm,ym);

g.drawLine(xcenter-1,ycenter,xm,ym);

g.drawLine(xcenter,ycenter-1,xh,yh);

g.drawLine(xcenter-1,ycenter,xh,yh);

lastxs=xs;lastys=ys;

lastxm=xm;lastym=ym;

lastxh=xh;lastyh=yh;

lastdate=today;

currentDate=null;

}

publicvoidpaint(Graphicsg){

g.setFont(clockFaceFont);

//Drawthecircleandnumbers

g.setColor(handColor);

g.drawArc(xcenter-50,ycenter-50,100,100,0,360);

g.setColor(numberColor);

g.drawString("9",xcenter-45,ycenter+3);

g.drawString("3",xcenter+40,ycenter+3);

g.drawString("12",xcenter-5,ycenter-37);

g.drawString("6",xcenter-3,ycenter+45);

//Drawdateandhands

g.setColor(numberColor);

g.drawString(lastdate,5,125);

g.drawLine(xcenter,ycenter,lastxs,lastys);

g.setColor(handColor);

g.drawLine(xcenter,ycenter-1,lastxm,lastym);

g.drawLine(xcenter-1,ycenter,lastxm,lastym);

g.drawLine(xcenter,ycenter-1,lastxh,lastyh);

g.drawLine(xcenter-1,ycenter,lastxh,lastyh);

}

publicvoidstart(){

timer=newThread(this);

timer.start();

}

publicvoidstop(){

timer=null;

}

publicvoidrun(){

Threadme=Thread.currentThread();

while(timer==me){

try{

Thread.currentThread().sleep(100);

}catch(InterruptedExceptione){

}

repaint();

}

}

publicStringgetAppletInfo(){

return"Title:

AClock\n"

+"Author:

RachelGollub,1995\n"

+"Ananalogclock.";

}

publicString[][]getParameterInfo(){

String[][]info={

{"bgcolor","hexadecimalRGBnumber",

"Thebackgroundcolor.Defaultisthecolorofyourbrowser."},

{"fgcolor1","hexadecimalRGBnumber",

"Thecolorofthehandsanddial.Defaultisblue."},

{"fgcolor2","hexadecimalRGBnumber",

"Thecolorofthesecondhandandnumbers.Defaultisdarkgray."}

};

returninfo;

}

}

3、定义一个可序列化的对象Student类,这个类实现了Serializable接口,类中的成员变量id,name,age,department都可以被序列化,方法不能序列化。

通过对象输出流的writeObject()方法将Student对象保存到文件data.ser中,然后通过对象输入流的readObject()方法从文件data.ser中读出保存下来的Student对象,然后将Student对象的id和name输出到控制台。

(25分)

importjava.io.FileInputStream;

importjava.io.FileNotFoundException;

importjava.io.FileOutputStream;

importjava.io.IOException;

importjava.io.ObjectInputStream;

importjava.io.ObjectOutputStream;

importjava.io.Serializable;

publicclassTest{

publicstaticvoidmain(Stringarg[]){

try{

Studentstudent=newStudent(2010030721,"胡思娥",21,"软件工程系");

ObjectOutputStreamoos=newObjectOutputStream(newFileOutputStream("data.ser"));

oos.writeObject(student);

ObjectInputStreamois=newObjectInputStream(newFileInputStream("data.ser"));

Students=(Student)ois.readObject();

s.display();

}

catch(Exceptione){

e.printStackTrace();

}

}

}

classStudentimplementsSerializable{

privateintid;

privateStringname;

privateintage;

privateStringdepartment;

publicStudent(intid,Stringname,intage,Stringdepartment){

this.id=id;

this.name=name;

this.age=age;

this.department=department;

}

publicvoiddisplay(){

System.out.println("id:

"+id+"name:

"+name);

}

}

4、编写一个异常类MyException,再编写一个类Student,该类有一个产生异常的方法publicvoidspeak(intm)throwsMyException,要求参数m的值大于1000时,方法抛出一个MyException对象。

最后编写主类,在主类的main方法中用Student创建一个对象,让该对象调用speak方法(m参数设为1500)。

(25分)

importjava.util.Scanner;

classMyExceptionextendsException

{

Stringmessage;

MyException(intm)

{

message="thenumber"+m+"greatthan1000";

}

publicStringtoString()

{

returnmessage;

}

}

classStudent

{

publicvoidspeak(intm)throwsMyException

{

if(m>1000)

{

MyExceptionex=newMyException(m);

throwex;

}

else

{

System.out.println("thenumberis:

"+m);

}

}

};

publicclassTest{

publicstaticvoidmain(Stringargs[])

{

Students=newStudent();

try

{

System.out.print("Pleaseinputnumber:

");

Scannernum=newScanner(System.in);

s.speak(num.nextInt());

}catch(MyExceptionmye)

{

System.out.println(mye.toString());

}

}

};

附加题:

5、有两个集合,A集合内容为:

{1、2、3、4},B集合内容为:

{1、2、5、6},两个集合的对称差定义为AΔB=(A−B)∪(B−A),上述A、B两集合的对称差为{3、4、5、6}。

编写一个程序,用散列集求两个集合A、B的对称差集合,即求

(20分)

importjava.util.*;

publicclassT{

publicstaticHashSeths1=newHashSet();

publicstaticHashSeths2=newHashSet();

publicstaticvoidinit()

{

Integer[]A={1,2,3,4};

Integer[]B={1,2,5,6};

for(inti=0;i

{

hs1.add(A[i]);

}

for(inti=0;i

{

hs2.add(B[i]);

}

}

publicstaticvoidmain(Stringargs[])

{

init();

for(Integeri:

hs1)

{

if(hs2.contains(i))

{

hs2.remove(i);

}

else

{

hs2.add(i);

}

}

System.out.println(hs2);

}

}

6访问Access2003数据库,在Access数据库中创建学生表(T_Student)表并配置ODBC驱动源,学生表的结构和示例数据如下所示:

T_Student表:

字段名称

说明

数据类型

约束

备注

S_ID

学号

Integer

主键

S_Name

姓名

Varchar(10)

不允许空

S_Email

邮箱

Varchar(30)

S_Score

英语成绩

Integer

表数据示例:

S_ID

S_Name

S_Email

S_Score

1001

Jerry

Jerry@

80

1002

Mike

Mike@

90

1003

John

John@

78

使用Java语言编写程序,插入3条记录,然后查询表数据并显示。

要求如下:

1)使用JDBC-ODBC桥驱动程序;

2)使用PreparedStatement语句来插入3条记录;

3)查询出表中所有记录,并按照主键升序显示。

参考

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 求职职场 > 简历

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2