全国自考Java语言程序设计一试题及答案解析Word下载.docx

上传人:b****2 文档编号:981567 上传时间:2023-04-29 格式:DOCX 页数:14 大小:74.52KB
下载 相关 举报
全国自考Java语言程序设计一试题及答案解析Word下载.docx_第1页
第1页 / 共14页
全国自考Java语言程序设计一试题及答案解析Word下载.docx_第2页
第2页 / 共14页
全国自考Java语言程序设计一试题及答案解析Word下载.docx_第3页
第3页 / 共14页
全国自考Java语言程序设计一试题及答案解析Word下载.docx_第4页
第4页 / 共14页
全国自考Java语言程序设计一试题及答案解析Word下载.docx_第5页
第5页 / 共14页
全国自考Java语言程序设计一试题及答案解析Word下载.docx_第6页
第6页 / 共14页
全国自考Java语言程序设计一试题及答案解析Word下载.docx_第7页
第7页 / 共14页
全国自考Java语言程序设计一试题及答案解析Word下载.docx_第8页
第8页 / 共14页
全国自考Java语言程序设计一试题及答案解析Word下载.docx_第9页
第9页 / 共14页
全国自考Java语言程序设计一试题及答案解析Word下载.docx_第10页
第10页 / 共14页
全国自考Java语言程序设计一试题及答案解析Word下载.docx_第11页
第11页 / 共14页
全国自考Java语言程序设计一试题及答案解析Word下载.docx_第12页
第12页 / 共14页
全国自考Java语言程序设计一试题及答案解析Word下载.docx_第13页
第13页 / 共14页
全国自考Java语言程序设计一试题及答案解析Word下载.docx_第14页
第14页 / 共14页
亲,该文档总共14页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

全国自考Java语言程序设计一试题及答案解析Word下载.docx

《全国自考Java语言程序设计一试题及答案解析Word下载.docx》由会员分享,可在线阅读,更多相关《全国自考Java语言程序设计一试题及答案解析Word下载.docx(14页珍藏版)》请在冰点文库上搜索。

全国自考Java语言程序设计一试题及答案解析Word下载.docx

8.在以下四个供选的整数中,能作为线程最高优先级的整数是()

A.0B.1

C.10D.11

9.Java语言可以用javax.swing包中的类JFileChooser来实现打开和保存文件对话框。

用户通过文件对话框不可能获得的信息是()

A.文件名称B.文件路径

C.文件内容D.文件对象

10.在编写访问数据库的Java程序时,Connection对象的作用是()

A.用来表示与数据库的连接B.存储查询结果

C.在指定的连接中处理SQL语句D.建立新数据库连接

二、填空题(本大题共10小题,每空2分,共20分)

请在每小题的空格中填上正确答案。

错填、不填均无分。

11.Java的编译程序先将Java源程序翻译成与机器无关的__________。

12.表达式¨

23&

18’’的值是__________。

13.如果类A某个成员变量的类型是类B,则类A和类B之间是__________关系。

14.Java语言提供了两个用于处理字符串的类,它们是__________。

15.某程序用代码“JTextFieldtext=newJTextField();

”创建了一个文本框,并对这个文本框注册了监视器,则在监视器处理方法actionPerformed(ActionEvente)中,判定是在这个文本框上发生事件的条件表达式是__________。

16.一个水平滚动条对象的初始值是50,滑块的宽是10个像素,表示的范围是[0,250]。

创建这样的滚动条对象时,提供的5个参数依次是__________。

17.要在JComponent子类的组件中绘图,应重写__________方法。

18.当线程使用完临界段后,为了使等待的线程恢复工作,需要调用的方法是__________。

19.某程序想为一个long型整数文件构造随机读写对象,支持这个要求的类是__________。

20.设已知服务器的IP地址和端口号,要创建一个套接字对象,支持这个要求的类是__________。

三、简答题(本大题共6小题,每小题3分,共18分)

21.请写出一段if语句,判断一个整数n是否为偶数。

如果是偶数,输出“Yes.”;

否则,输出“No.”。

22.请写出接口定义的一般形式。

23.请写出Java语言编写事件处理程序的两种主要方案。

24.设已经有Graphics2D对象g2d,请用Java语句绘制一个矩形rect,其左上角坐标是(20,30),宽是120,高是30。

25.打开文件对话框时,还可以设置筛选条件,即指定文件的类型。

请写出FileFilter类预设的两个方法。

26.请写出URLConnection类提供的三个常用方法。

四、程序填空题(本大题共5小题,每空2分,共20分)

27.方法voidmoveOddForword(inta[])的功能是将数组中的所有奇数移到所有偶数之前。

voidmoveOddForword(inta[]){

for(inti=0,odd=0;

________;

i++)

if(________){

intt=a[i];

a[i]=a[odd];

a[odd]=t;

odd++;

}

}

28.以下程序创建了一个窗口,然后在窗口内显示″Hello,World!

″。

importjavax.swing.*;

importjava.awt*;

publicclassHelloWorld{

publicstaticvoidmain(String[]ares){

TextFrameframe=newTextFrame();

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.________;

}

classTextFrameextendsJFrame{

publicTextFrame(){.

setTitle(″HelloWorld″);

setSize(WIDTH,HEIGHT);

TextPanelpanel=newTextPanel();

ContainercontentPane=getContentPane();

contentPane.add(panel);

publicstaticfinalintWIDTH=300;

publicstaticfinalintHEIGHT=200;

classTextPanelextendsJPanel{

publicvoidpaintComponent(Graphicsg){

super.________;

g.drawString(″Hello,World!

″,x,y);

publicintx=100;

publicinty=100;

29.以下是子窗口中设置一个菜单条类的定义。

类的构造方法根据指定的窗口名称和菜单表设置菜单条,菜单和菜单项,当选中某个菜单项时,在文本框中显示相应菜单项被选中的信息。

classMenuWindowextendsJFrameimplementsActionListener{

publicstaticJTextFieldtext;

publicMenuWindow(Strings,StringmenuList[][]){

setTitle(s);

Containercon=this.getContentPane();

con.setLayout(newBorderLayout());

this.setLocation(100,100);

this.setSize(300,100);

JMenuBarmenubar=newJMenuBar();

for(inti=0;

i<

menuList.length;

i++){

JMenumenu=newJMenu(menuList[i][0]);

for(intj=1;

j<

menuList[i].1ength;

j++){

JMenultemanltem=newJMenultem(menuList[i][j]);

anltem.setActionCommand(menuList[i][j]);

anltem.________;

menu.add(anltem);

menubar.__________;

text=newJTextField();

setJMenuBar(menubar);

con.add(text,BorderLayout.SOUTH);

publicvoidactionPerformed(ActionEvente){

text.setText(e.getActionCommand()+″菜单项被选中!

″);

publicclassTest29extendsApplet{

MenuWindowwindow;

StringmenuList[][]={{″体育″,″跑步″,″打蓝球″,″打乒乓″},

{″娱乐″,″唱歌″,″跳舞″}};

publicvoidinit(){

window=newMenuWindow(″体育娱乐之窗″,menuList);

window.setVisible(true);

30.以下是一个用鼠标自由作画的小应用程序。

最简单的方法是根据鼠标所在位置画点,跟随鼠标的移动,不断画圆点,就能实现用鼠标作画。

importjava.awt.*;

importjava.awt.event.*;

publicclassTest30extendsjava.applet.AppletimplementsMouseMotionListener{

Colorcolor;

intlineSize=2:

intx=-1,y=-l;

publicvoidinit(){

setLocation(30,20);

setSize(300,300);

setBackground(Color.green);

addMouseMotionListener(this);

publicvoidpaint(Graphicsg){

if(x!

=-1&

&

y!

=-1){

g.setColor(color);

g.fillOval(x,y,1ineSize,lineSize);

publicvoidmouseMoved(MouseEvente){}

publicvoidmouseDragged(MouseEvente){

x=e.getX();

y=e.getY();

_________;

publicvoid________(Graphicsg){paint(g);

}

31.以下定义的类ShareData用于管理多个线程共享数据data。

一个线程生成data,另一个线程使用data。

约定,新生成的data只有被另一个线程使用后,才能生成下一个data。

反之,一个data被使用后,也不能再继续使用。

所以,生成和使用data的线程之间需要互斥和同步。

以下是管理上述使用方式的类,类内有要管理的共享数据,以及对共享数据的存操作putData()和取操作getData()。

classShareData{

intdata;

∥共享数据

booleannewData=false;

∥有最近新生成data的标志

synchronizedintgetData(){

while(!

newData){

try{_________;

}catch(InterruptedExceptipne){

System.out.println(″因错误,而中断!

″);

newData=false;

notify();

returndata;

synchronizedvoidputData(intn){

while(newData){

try{wait();

}catch(InterruptedExceptione){

data=n;

__________;

return;

五、程序分析题(本大题共5小题,每小题4分,共20分)

32.阅读下列程序,请写出该程序的输出结果。

classParent{

privatevoidmethod1(){System.out.println(″Parent′smethod1()″);

publicvoidmethod2(){System.out.println(″Parent′smethod2()″);

method1();

classChildextendsParent{

publicvoidmethodl(){System.out.println(″Child′smethod1()″);

publicstaticvoidmain(Stringargs[]){Parentp=newChild();

p.method2();

33.阅读下列程序,请写出该程序的功能。

importjava.util.*;

importjavax.swing.*;

publicclassTest33{

publicstaticvoidmain(Stringargs[]){

Stringstr=(String)JOptionPane.showInputDialog(null,″请输入信息″,

″输入对话框″,JOptionPane.PLAIN_MESSAGE,null,null,null);

StringTokenizerpas=newStringTokenizer(str,″,″);

intn=pas.countTokens();

System.out.println(″输入的信息有单词:

″+n+″个,全部单词如下:

while(pas.hasMoreTokens()){

Strings=pas.nextToken();

System.out.println(s);

34.阅读下列程序,请用示意图画出程序运行时呈现的界面。

importjava.applet.*;

importjava.awt.*;

classMyPanelextendsJPanel{

JTextFieldtextl,text2;

MyPanel(Stringsl,Strings2){

textl=newJTextFieId(s1);

text2=newJTextField(s2);

add(text1);

add(text2);

classMySubPanelextendsMyPanel{

JTextFieldtext;

MySubPanel(Stringsl,Strings2,Strings3){

super(s1,s2);

text=newJTextField(s3);

add(text);

publicclassTest34{

publicstaticvoidmain(Stringargs[]){

JFramemw=newJFrame(″一个示意窗口″);

mw.setSize(350,150);

Containercon=mw.getContentPane();

con.setLayout(newBorderLayout());

MyPanelpl=newMyPanel(″文本框l″,″文本框2″);

MySubPanelp2=newMySubPanel(″文本框3″,″文本框4″,″文本框5″);

JTextAreatext=newJTextArea(″这里是一个文本区″);

con.add(pl,″North″);

con.add(p2,″South″);

con.add(text,″Center″);

mw.setVisible(true);

35.阅读下列程序,请写出该程序的功能。

importjava.applet.*:

importjava.awt.event.*;

importjavax.swing.*

publicclassClass1extendsAppletimplementsKeyListener{

JButtonbutton=newJButton(″开始″);

JTextAreatext=newJTextArea(5,20);

publicvoidinit(){

button.addKeyListener(this);

add(button);

publicvoidkeyPressed(KeyEvente){

intt=e.getKeyCode();

if(t>

=KeyEvent.VK_A&

t<

=KeyEvent.VK_Z){

text.append(″″+(char)t);

publicvoidkeyTyped(KeyEvente){}

publicvoidkeyReleased(KeyEvente){}

36.阅读下列程序,请写出该程序的功能。

importjava.awt.*;

publicclassTest36extendsjava.applet.AppletimplementsRunnable{

ThreadmyThread=null;

doubleseta=0.0;

publicvoidstart(){

setSize(500,400);

if(myThread=null){myThread=newThread(this);

myThread.start();

publicvoidrun(){

while(myThread!

=null){

try{myThread.sleep(40);

}catch(InterruptedExceptione){}

seta+=3.0;

if(seta>

=360)seta=0;

repaint();

publicvoidpaint(Graphicsg){

finaldoublepi=3.14159;

finaldoubler=100.0;

intx0=250+(int)(r*Math.cos(3.1415926/180.0*seta));

inty0=200+(int)(r*Math.sin(3.1415926/180.0*seta));

g.setColor(Color.red);

g.drawOval(x0,y0,10,10);

六、程序设计题(本大题共2小题,每小题6分,共12分)

37.请编写方法voidstrReverse(Stringstr),该方法的功能是输出一个新字符串,新字符串字符排列顺序与原字符串str的字符排列顺序相反。

例如,strReverse(″ABCD″)所输出的结果是″DCBA″。

请使用字符串与字节数组的相互转换方法进行设计。

38.请设计实现如下用于输入学号和姓名的对话框界面,其中空白格是文本框,用于输入相应的内容。

这里给出的是程序的一部分,你要编写的是类InputNoNameDialog的构造方法InputNoNameDialog(JFramef,Strings,JTextFieldt)。

其中参数f是对话框的依赖窗口,s是对话框标题,t是依赖窗口中显示对话框输入内容的文本框。

以下是类InputNoNameDialog的程序框架。

classInputNoNameDialogextendsJDialogimplementsActionListener{

JLabeltitle;

JTextFieldtextl,text2,mainText;

JButtondone;

InputNoNameDialog(JFramefStrings,JTextFieldt){

super(f,s,true);

mainText=t;

Containercon=getContentPane();

title=newJLabel(s);

textl=newJTextField(10);

text2=newJTextField(10);

con.setLayout(newGridLayout(3,2));

con.setSize(200,100);

setModal(false);

//请在以下位置续写其余代码

 

publicvoidactionPerformed(ActionEvente){

//输入结束按确定按钮后,将对话框中输入的学号和姓名在它依赖窗口的文本框中显示。

mainText.setText(″学号:

″+textl.getText()+″姓名:

″+text2.getText());

setVisible(false);

dispose();

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

当前位置:首页 > 法律文书 > 调解书

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

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