




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、更多優(yōu)質(zhì)自考資料盡在百度貼吧自考樂園俱樂部(全國2010年1月自考java語言程序設(shè)計(一)試題課程代碼:04747一、單項選擇題(本大題共10小題,每小題1分,共10分)在每小題列出的四個備選項中只有一個是符合題目要求的,請將其代碼填寫在題后的括號內(nèi)。錯選、多選或未 選均無分。1在下述字符串中,不屬于java語言關(guān)鍵字的是 ( )afloat bnewcjava dreturn2java語言中數(shù)值數(shù)據(jù)的類型能自動轉(zhuǎn)換,按照從左到右的轉(zhuǎn)換次序為 ( )a byteintshortlongfloatdoubleb byteshortintlongfloatdoublec byteshortint
2、floatlongdoubled shortbyteintlongfloatdouble3在以下供選擇的概念中,不屬于面向?qū)ο笳Z言概念的是 ( )a消息 b模塊c繼承 d多態(tài)性4在下述java語言語句中,錯誤的創(chuàng)建數(shù)組的方法是 ( )aint intarray ; intarray=new int5;bint intarray =new int5;cint intarray =1,2,3,4,5;dint intarray 5=1,2,3,45;5在swing中,它的子類能用來創(chuàng)建框架窗口的類是 ( )ajwindow bjframecjdialog djapplet6mouselistene
3、r接口不能處理的鼠標事件是 ( )a按下鼠標左鍵 b點擊鼠標右鍵c鼠標進入 d鼠標移動7以下不屬于文字字型要素的是 ( )a顏色 b字體c風(fēng)格 d字號8在以下四個供選的整數(shù)中,能作為線程最高優(yōu)先級的整數(shù)是 ( )a0 b1c10 d119java語言可以用javax.swing包中的類jfilechooser來實現(xiàn)打開和保存文件對話框。用戶通過文件對話框不可能獲得的信息是 ( )a文件名稱 b文件路徑c文件內(nèi)容 d文件對象10在編寫訪問數(shù)據(jù)庫的java程序時,connection對象的作用是 ( )a用來表示與數(shù)據(jù)庫的連接 b存儲查詢結(jié)果c在指定的連接中處理sql語句 d建立新數(shù)據(jù)庫連接二、填
4、空題(本大題共10小題,每空2分,共20分)請在每小題的空格中填上正確答案。錯填、不填均無分。11java的編譯程序先將java源程序翻譯成與機器無關(guān)的_。字節(jié)碼12表達式¨23 & 18的值是_。 231813如果類a某個成員變量的類型是類b,則類a和類b之間是_關(guān)系。(p57)has-a14java語言提供了兩個用于處理字符串的類,它們是_。stringstringbuffer15某程序用代碼“jtextfield text=new jtextfield();”創(chuàng)建了一個文本框,并對這個文本框注冊了監(jiān)視器,則在監(jiān)視器處理方法actionperformed(actionev
5、ent e)中,判定是在這個文本框上發(fā)生事件的條件表達式是_。e.getsource()=text16一個水平滾動條對象的初始值是50,滑塊的寬是10個像素,表示的范圍是0,250。 創(chuàng)建這樣的滾動條對象時,提供的5個參數(shù)依次是_。(p125)jscrollbar.horizontal,50,10,0,25017要在jcomponent 子類的組件中繪圖,應(yīng)重寫_方法。paintcomponet()18當(dāng)線程使用完臨界段后,為了使等待的線程恢復(fù)工作,需要調(diào)用的方法是_。notify()19某程序想為一個long型整數(shù)文件構(gòu)造隨機讀寫對象,支持這個要求的類是_。randomaccessfile2
6、0設(shè)已知服務(wù)器的ip地址和端口號,要創(chuàng)建一個套接字對象,支持這個要求的類是_。socket三、簡答題(本大題共6小題,每小題3分,共18分)21請寫出一段if語句,判斷一個整數(shù)n是否為偶數(shù)。如果是偶數(shù),輸出“yes.”;否則,輸出“no”。 if(n%2=0)system.out.println(“yes”);elssystem.out.println(“no”);22請寫出接口定義的一般形式。(p59)23請寫出java語言編寫事件處理程序的兩種主要方案。(p87)24設(shè)已經(jīng)有g(shù)raphics2d對象g2d, 請用java語句繪制一個矩形rect,其左上角坐標是(20,30),寬是120,高
7、是30。 rectangle2d rect=new rectangle2d.double(20,30,120,30) g2d.draw(rect);25打開文件對話框時,還可以設(shè)置篩選條件,即指定文件的類型。請寫出filefilter類預(yù)設(shè)的兩個方法。accept() getdescription()26請寫出urlconnection類提供的三個常用方法。 getoutputstream() getinputstream() connect()四、程序填空題(本大題共5小題,每空2分,共20分)27方法void moveoddforword(int a )的功能是將數(shù)組中的所有奇數(shù)移到所有偶
8、數(shù)之前。 void moveoddforword(int a) for(int i=0, odd=0;_;i+) i<a.length if(_) ai%2= =0 int t=ai;ai=aodd;aodd=t;odd+; 28以下程序創(chuàng)建了一個窗口,然后在窗口內(nèi)顯示hello,world! 。 import javax.swing.*; import javaawt*; public class helloworld public static void main(string ares) textframe frame=new textframe(); frame.setdefau
9、ltcloseoperation(jframe.exit_on_close); frame. _; setvisable(true) class textframe extends jframe public textframe() settitle(helloworld); setsize(width,height); textpanel panel=new textpanel(); container contentpane=getcontentpane(); contentpaneadd(panel); public static final int width=300; public
10、static final int height= 200; class textpanel extends jpanel public void paintcomponent(graphics g) super. _; paintcomponent(g) g.drawstring(hello,world! ,x,y); public int x=100; public int y=100; 29以下是子窗口中設(shè)置一個菜單條類的定義。類的構(gòu)造方法根據(jù)指定的窗口名稱和菜單表設(shè)置菜單條,菜單和菜單項,當(dāng)選中某個菜單項時,在文本框中顯示相應(yīng)菜單項被選中的信息。 class menuwindow ext
11、ends jframe implements actionlistener public static jtextfield text; public menuwindow(string s,string menulist) settitle(s); container con=this.getcontentpane(); con.setlayout(new borderlayout(); this.setlocation(100,100); this.setsize(300,100); jmenubar menubar=new jmenubar(); for(int i=0; i<me
12、nulist.length;i+) jmenu menu=new jmenu(menulisti0); for(int j=1;j<menulisti1ength;j+) jmenultem anltem=new jmenultem(menulistij); anltemsetactioncommand(menulistij); anltem_;menu.add(anltem); actionlistener(this) menubar_; add(menu) text=new jtextfield();setjmenubar(menubar); con.add(text,borderl
13、ayoutsouth); public void actionperformed(actionevent e) textsettext(egetactioncommand()+菜單項被選中! ); public class test29 extends applet menuwindow window; string menulist=體育,跑步,打藍球,打乒乓, 娛樂,唱歌,跳舞; public void init() window=new menuwindow(體育娛樂之窗,menulist); window.setvisible(true); 30以下是一個用鼠標自由作畫的小應(yīng)用程序。最
14、簡單的方法是根據(jù)鼠標所在位置畫點,跟隨鼠標的移動,不斷畫圓點,就能實現(xiàn)用鼠標作畫。import javaawt.*; import javaawt.event.*; public class test30 extends javaappletapplet implements mousemotionlistener color color;int linesize=2: int x=-1,y=-l; public void init() setlocation(30,20); setsize(300,300); setbackground(color.green);addmousemotion
15、listener(this); public void paint(graphics g) if(x!=-1&&y!=-1) g.setcolor(color);g.filloval(x,y,1inesize,linesize); public void mousemoved(mouseevent e) public void mousedragged(mouseevent e) x=e.getx();y=egety();_; repaint() public void _ (graphics g) paint(g); update(); 31以下定義的類sharedata用于
16、管理多個線程共享數(shù)據(jù)data。一個線程生成data,另一個線程使用data。約定,新生成的data只有被另一個線程使用后,才能生成下一個data。反之,一個data被使用后,也不能再繼續(xù)使用。所以,生成和使用data的線程之間需要互斥和同步。以下是管理上述使用方式的類,類內(nèi)有要管理的共享數(shù)據(jù),以及對共享數(shù)據(jù)的存操作putdata()和取操作getdata()。class sharedata int data;共享數(shù)據(jù) boolean newdata=false;有最近新生成data的標志 synchronized int getdata() while(!newdata) try _; wai
17、t() catch(interruptedexceptipn e) system.out.println(因錯誤,而中斷!); newdata=false; notify();return data; synchronized void putdata(int n) while(newdata) trywait(); catch(interruptedexception e) system.out.println(因錯誤,而中斷! ); data=n; _; newdata=true notify(); return; 五、程序分析題(本大題共5小題,每小題4分,共20分)32閱讀下列程序,請
18、寫出該程序的輸出結(jié)果。 class parent private void method 1 () system.out.println(parents method 1(); public void method 2 () system.out.println(parents method 2();method 1(); class child extends parent public void method l () system.out.println(childs method 1 (); public static void main(string args) parent p =
19、 new child();p.method2(); parents method 2()parents method 1()33閱讀下列程序,請寫出該程序的功能。 import java.util.*;import javax.swing.*; public class test33 public static void main(string args)string str=(string)joptionpaneshowinputdialog(null,請輸入信息,輸入對話框,joptionpaneplain_message,null,null,null);stringtokenizer p
20、as=new stringtokenizer(str, ,);int n=pas.counttokens();system.out.println(輸入的信息有單詞:+n+個,全部單詞如下:);while(pashasmoretokens()string s=pas.nexttoken();system.out.println(s); )在輸入對話框中輸入文字,并以多好作為分割符輸出單詞個數(shù),及各個單詞34閱讀下列程序,請用示意圖畫出程序運行時呈現(xiàn)的界面。 import java.applet.*;import java.awt.*;import javax.swing.*; class my
21、panel extends jpanel jtextfield textl,text2; mypanel(string sl,string s2) textl=new jtextfieid(s1); text2=new jtextfield(s2); add(text 1); add(text2); class mysubpanel extends mypanel jtextfield text; mysubpanel(string sl,string s2,string s3) super(s1,s2);text = new jtextfield(s3);add(text); public
22、class test34 public static void main(string args) jframe mw=new jframe(一個示意窗口); mw.setsize(350,150); container con = mw.getcontentpane(); con.setlayout(new borderlayout(); mypanel pl=new mypanel(文本框l,文本框2); mysubpanel p2=new mysubpanel(文本框3,文本框4,文本框5); jtextarea text=new jtextarea(這里是一個文本區(qū)); con.add
23、(pl,north); con.add(p2,south); con.add(text,center);mwsetvisible(true); 35閱讀下列程序,請寫出該程序的功能。 import java.applet.*:import java.awt.event.*;import javax.swing.* public class class 1 extends applet implements keylistener jbutton button=new jbutton(開始); jtextarea text=new jtextarea(5,20); public void ini
24、t() button.addkeylistener(this); add(button);add(text); public void keypressed(keyevent e) int t=e.getkeycode(); if(t>=keyevent.vk_a&& t<=keyevent.vk_z) text.append( +(char)t); public void keytyped(keyevent e) public void keyreleased(keyevent e) 程序功能:從鍵盤輸入字符如果是大寫字母a-z,則顯示在文本區(qū)中36.閱讀下列程序
25、,請寫出該程序的功能。 import java.applet.*; import java.awt.*; public class test36 extends java.applet.applet implements runnable thread mythread = null; double seta=0.0; public void start() setsize(500,400); if(mythread=null) mythread=new thread(this); mythread.start(); public void run() while(mythread!=null
26、) try mythread.sleep(40); catch(interruptedexception e) seta+=3.0; if(seta>=360)seta=0; repaint(); public void paint(graphics g) final double pi=3.14159; final double r = 100.0; int x0=250+(int)(r*math.cos(3.1415926/180.0*seta); int y0=200+(int)(r*math.sin(3.1415926/180.0*seta); g.setcolor(color.
27、red); g.drawoval(x0,y0,10,10); 紅色、順時針畫圓六、程序設(shè)計題(本大題共2小題,每小題6分,共1 2分)37.請編寫方法void strreverse(string str),該方法的功能是輸出一個新字符串,新字符串字符排列順序與原字符串str的字符排列順序相反。例如,strreverse(abcd) 所輸出的結(jié)果是dcba。請使用字符串與字節(jié)數(shù)組的相互轉(zhuǎn)換方法進行設(shè)計。public static void strreverse(string str) byte s=str.getbytes(); string t="" for(int i=s.length-1;i>=0;i-) t+=(char)si; system.out.println(t); 38.請設(shè)計實現(xiàn)如下用于輸入學(xué)號和姓名的對話框界面,其中空白格是文本框,用于輸入相應(yīng)的內(nèi)容。這里給出的是程序的一部分,你要編寫的是類inputnonamedialog的構(gòu)造方法inputnonamedialog(jframe f,string s,jtextfield t)。其中參數(shù)f是對話框的依賴窗口,s
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 委托審計服務(wù)合同協(xié)議書
- 駕校合同解除協(xié)議
- 報名協(xié)議合同
- 全款購車協(xié)議合同
- 卡車租車協(xié)議合同
- 耗材合同空檔期補充協(xié)議
- 補充協(xié)議增加合同當(dāng)事人
- 違反合同賠償協(xié)議
- 油漆合同協(xié)議范本
- 包過協(xié)議合同
- 2025年浙江長征職業(yè)技術(shù)學(xué)院高職單招職業(yè)技能測試近5年??及鎱⒖碱}庫含答案解析
- 2024-2030年中國便攜式超聲行業(yè)市場發(fā)展監(jiān)測及投資潛力預(yù)測報告
- 《習(xí)作:我的“自畫像”》說課稿-2023-2024學(xué)年四年級下冊語文統(tǒng)編版001
- 2025無人駕駛視覺識別技術(shù)
- 湖南省長沙市雨花區(qū)2024-2025學(xué)年高一上學(xué)期期末考試英語試卷 含解析
- 企業(yè)職務(wù)犯罪法制講座
- 【農(nóng)學(xué)課件】瓜類蔬菜栽培
- IATF16949體系推行計劃(任務(wù)清晰版)
- 2024年軍事理論知識全冊復(fù)習(xí)題庫及答案
- 2023年江蘇皋開投資發(fā)展集團有限公司招聘筆試真題
- 任務(wù) 混合動力汽車空調(diào)系統(tǒng)典型構(gòu)造與檢修
評論
0/150
提交評論