試卷課程代碼:04747一、單項選擇題(本大題共10小題,每小題1分,共10分>在每小題列出的四個備選項中只有一個是符合題目要求的,請將其代碼填寫在題后的括號內。錯選、多選或未選均">

午夜大胆裸体a级人体片,无码人妻久久一区二区三区免费,午夜伦理在线观看一区二区三区,无码日韩人妻av一区二区三区,日韩一区二区三免费高清

>

2018年01月自學考試04747《Java語言程序設計(一)》試題

來源 : 湖北自考學院 更新時間 : 2019-08-14 瀏覽次數 : 863

導讀:提供月全國自考Java語言程序設計方案(一)真題及答案文檔免費下載,摘要:全國2018年1月自考Java語言程序設計(一>試卷課程代碼:04747一、單項選擇題(本大題共10小題,每小題1分,共10分>在每小題列出的四個備選項中只有一個是符合題目要求的,請將其代碼填寫在題后的括號內。錯選、多選或未選均

全國2018年1月自考Java語言程序設計(一>試卷

課程代碼:04747

一、單項選擇題(本大題共10小題,每小題1分,共10分>

在每小題列出的四個備選項中只有一個是符合題目要求的,請將其代碼填寫在題后的括號內。錯選、多選或未選均無分。

1.在下述字符串中,不屬于Java語言關鍵字的是(  )

A.float B.new

C.java D.return

2.Java語言中數值數據的類型能自動轉換,按照從左到右的轉換次序為(  )

A. byte→int→short→long→float→double

B. byte→short→i nt→l ong→fl oat→double

C. byte→sho rt→int→float→long→double

D. short→byte→int→l ong→float→double

3.在以下供選擇的概念中,不屬于面向對象語言概念的是 (  )

A.消息B.模塊

C.繼承D.多態(tài)性

4.在下述Java語言語句中,錯誤的創(chuàng)建數組的方法是(  )

A.int intArray[];intArray=new int[5];

B.int intArray[]=new int[5];

C.int[ ] intArray ={1,2,3,4,5};

D.int intArray[5]={1,2,3,4.5}。

5.在Swing中,它的子類能用來創(chuàng)建框架窗口的類是(  )

A.JWindow B.JFrame

C.JDialog D.JApplet

6.MouseListener接口不能處理的鼠標事件是 (  )

A.按下鼠標左鍵B.點擊鼠標右鍵

C.鼠標進入D.鼠標移動

7.以下不屬于文字字型要素的是(  )

A.顏色B.字體

C.風格D.字號

8.在以下四個供選的整數中,能作為線程最高優(yōu)先級的整數是(  )

A.0 B.1

C.10 D.11

9.Java語言可以用javax.swing包中的類JFileChooser來實現(xiàn)打開和保存文件對話框。用戶通過文件對話框不可能獲得的信息是 (  )

A.文件名稱B.文件路徑

C.文件內容D.文件對象

10.在編寫訪問數據庫的Java程序時,Connection對象的作用是(  )

A.用來表示與數據庫的連接B.存儲查詢結果

C.在指定的連接中處理SQL語句D.建立新數據庫連接

二、填空題(本大題共10小題,每空2分,共20分>

請在每小題的空格中填上正確答案。錯填、不填均無分。

11.Java的編譯程序先將Java源程序翻譯成與機器無關的__________。字節(jié)碼

12.表達式¨23&18’’的值是__________。

13.如果類A某個成員變量的類型是類B,則類A和類B之間是__________關系。

14.Java語言提供了兩個用于處理字符串的類,它們是__________。String\StringBuffer

15.某程序用代碼“JTextField text=new JTextField<);”創(chuàng)建了一個文本框,并對這個文本框注冊了監(jiān)視器,則在監(jiān)視器處理方法actionPerformed (ActionEvent e>中,判定是在這個文本框上發(fā)生事件的條件表達式是__________。e.getSource(>==text 

16.一個水平滾動條對象的初始值是50,滑塊的寬是10個像素,表示的范圍是[0,250]。

創(chuàng)建這樣的滾動條對象時,提供的5個參數依次是__________。(P125>JScrollBar.HORIZONTAL,50,10,0,25 0

17.要在JComponent 子類的組件中繪圖,應重寫__________方法。paintComponet(>

18.當線程使用完臨界段后,為了使等待的線程恢復工作,需要調用的方法是__________。Notify(> 19.某程序想為一個long型整數文件構造隨機讀寫對象,支持這個要求的類是__________。RandomAcces sFile

20.設已知服務器的IP地址和端口號,要創(chuàng)建一個套接字對象,支持這個要求的類是__________。Socket 三、簡答題(本大題共6小題,每小題3分,共18分>

21.請寫出一段if語句,判斷一個整數n是否為偶數。如果是偶數,輸出“Yes.”;否則,輸出“No.”。

If(n%2==0>{System.out.println(“Yes”>。}els{System.out.println(“No”>。}

22.請寫出接口定義的一般形式。

23.請寫出Java語言編寫事件處理程序的兩種主要方案。

24.設已經有Graphics2D對象g2d,

請用Java語句繪制一個矩形rect,其左上角坐標是(20,30>,寬是120,高是30。

Rectangle2D rect=new Rectangle2D.Double(20,30,120,30>

G2d.draw(rect>。

25.打開文件對話框時,還可以設置篩選條件,即指定文件的類型。請寫出FileFilter類預設的兩個方法。accept(> getDescription(>

26.請寫出URLConnection類提供的三個常用方法。

getOutputStream(>

getInputStream(>

connect(>

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

27.方法void moveOddForword(int a[]>的功能是將數組中的所有奇數移到所有偶數之前。

void moveOddForword(int a[]>{

for(int i=0, odd=0。________;i++>i

if(________>{ a[i]%2= =0

int t=a[i];a[i]=a[odd];a[odd]=t;odd++;

}

}

28.以下程序創(chuàng)建了一個窗口,然后在窗口內顯示″Hello,World!″。

importjavax.swing.*; importjava.awt*;

public class HelloWorld{

public static void main(String[]ares> {

TextFrame frame=new TextFrame(>;

frame.setDefaultCloseOperation(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(>;

contentPane.add(panel>;

}

public static final int WIDTH=300;

public 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.以下是子窗口中設置一個菜單條類的定義。類的構造方法根據指定的窗口名稱和菜單表設置菜單條,菜單和菜單項,當選中某個菜單項時,在文本框中顯示相應菜單項被選中的信息。

class MenuWindow extends 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{

JMenu menu=new JMenu(menuList[i][0]>;

for(intj=1;j{

JMenultem anltem=new JMenultem(menuList[i][j]>;

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

anltem.________;menu.add(anltem>;ActionListener(this>

}

menubar.__________;add(menu>

}

text=new JTextField(>;setJMenuBar(menubar>;

con.add(text,BorderLayout.SOUTH>;

}

public void actionPerformed(ActionEvent e>{

text.setText(e.getActionCommand(>+″菜單項被選中!″>;

}

}

public class Test29 extends Applet{

MenuWindow window;

String menuList[][]={{″體育″,″跑步″,″打藍球″,″打乒乓″},

{″娛樂″,″唱歌″,″跳舞″}};

public void init(> {

window=new MenuWindow(″體育娛樂之窗″,menuList>;

window.setVisible(true>。

}

}

30.以下是一個用鼠標自由作畫的小應用程序。最簡單的方法是根據鼠標所在位置畫點,跟隨鼠標的移動,不斷畫圓點,就能實現(xiàn)用鼠標作畫。

import java.awt.*;

import java.awt.event.*;

public class Test30 extends java.applet.Applet implements MouseMotionListener {

Color color;int lineSize=2:

int x=-1,y=-l;

public void init(>{

setLocation(30,20>; setSize(300,300>;

setBackground(Color.green>;addMouseMotionListener(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=e.getY(>;_________;repaint(>

}

public void ________ (Graphics g>{paint(g>;} update(>。

}

31.以下定義的類ShareData用于管理多個線程共享數據data。一個線程生成data,另一個線程使用data。約定,新生成的data只有被另一個線程使用后,才能生成下一個data。反之,一個data被使用后,也不能再繼續(xù)使用。所以,生成和使用data的線程之間需要互斥和同步。以下是管理上述使用方式的類,類內有要管理的共享數據,以及對共享數據的存操作putData(>和取操作getData(>。

class ShareData{

int data;∥共享數據

boolean newData=false;∥有最近新生成data的標志

synchronized int getData(>{

while(!newData>{

try{ _________; wait(>

} catch(InterruptedExceptipn e>{

System.out.println(″因錯誤,而中斷!″>;

}

}

newData=false; notify(>;return data;

}

synchronized void putData(int n>{

while(newData>{

try{wait(>;

}catch(InterruptedException e>{

System.out.println(″因錯誤,而中斷!″>;

}

}

data=n; __________; newData=true

notify(>; return;

}

}

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

32.閱讀下列程序,請寫出該程序的輸出結果。

class Parent{

private void method 1 (>{ System.out.println(″Parent′s method 1(>″>;}

public void method2 (> { System.out.println(″Parent′s method2(>″>;method 1(>;}

}

class Child extends Parent{

public void method l (>{System.out.println(″Child′s method 1 (>″>;}

public static void main(String args[]>{Parent p= new Child(>;p.method2(>;}

}

Parent′s method 2(>

Parent′s method 1(>

33.閱讀下列程序,請寫出該程序的功能。

importjava.util.*;importjavax.swing.*;

public class Test33{

public static void main(String args[]>{

String str=(String>JOptionPane.showInputDialog(null,″請輸入信息″,

″輸入對話框″,JOptionPane.PLAIN_MESSAGE,null,null,null>;

StringTokenizer pas=new StringTokenizer(str,″,″>;

int n=pas.countTokens(>;

System.out.println(″輸入的信息有單詞:″+n+″個,全部單詞如下:″>;

while(pas.hasMoreTokens(>>{

String s=pas.nextToken(>;

System.out.println(s>;

}

}

>

在輸入對話框中輸入文字,并以多好作為分割符輸出單詞個數,及各個單詞

34.閱讀下列程序,請用示意圖畫出程序運行時呈現(xiàn)的界面。

importjava.applet.*;importjava.awt.*;importjavax.swing.*;

class MyPanel extends JPanel{

JTextField textl,text2;

MyPanel(Stringsl,Strings2>{

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 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(pl,″North″>; con.add(p2,″South″>;

con.add(text,″Center″>;mw.setVisible(true>;

}

}

月全國自考Java語言程序設計方案(一)真題及答案

35.閱讀下列程序,請寫出該程序的功能。

importjava.applet.*:importjava.awt.event.*;importjavax.swing.*

public class Class 1 extends Applet implements KeyListener{

JButton button=new JButton(″開始″>;

JTextArea text=new JTextArea(5,20>;

public void init(> {

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.閱讀下列程序,請寫出該程序的功能。

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>{

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.red>; g.drawOval(x0,y0,10,10>;

}

}

紅色、順時針畫圓

六、程序設計題(本大題共2小題,每小題6分,共1 2分>

37.請編寫方法void strReverse(String str>,該方法的功能是輸出一個新字符串,新字符串字符排列順序與原字符串str的字符排列順序相反。例

如,strReverse(″ABCD″> 所輸出的結果是″DCBA″。請使用字符串與字節(jié)數組的相互轉換方法進行設計。publicstaticvoid strReverse(String str>{

byte[] s=str.getBytes(>。

String t=""。

for(int i=s.length-1。i>=0。i-->{

t+=(char>s[i]。

}

System.out.println(t>。

}

38.請設計實現(xiàn)如下用于輸入學號和姓名的對話框界面,其中空白格是文本框,用于輸入相應的內容。

月全國自考Java語言程序設計方案(一)真題及答案

這里給出的是程序的一部分,你要編寫的是類InputNoNameDialog的構造方法InputNoNameDialog(JFram e f,String s,JTextField t>。其中參數f是對話框的依賴窗口,s是對話框標題,t是依賴窗口中顯示對話框輸入內容的文本框。

以下是類InputNoNameDialog的程序框架。

class InputNoNameDialog extends JDialog implements ActionListener{

JLabel title;JTextField textl,text2,mainText;JButton done;

InputNoNameDialog(JFrame f,String s,JTextField t>{

super(f,s,true>; mainText = t;Container con = getContentPane(>;

title=new JLabel(s>;textl=new JTextField(10>;

text2=new JTextField(10>;con.setLayout(new GridLayout(3,2>>;

con.setSize(200,100>; setModal(false>;

//請在以下位置續(xù)寫其余代碼

done=new JButton("確定">。

done.addActionListener(this>。

con.add(title>。con.add(done>。

con.add(new JLabel("學號">>。con.add(textl>。

con.add(new JLabel("姓名">>。con.add(text2>。

setVisible(true>。}

public void actionPerformed(ActionEvent e>{

//輸入結束按確定按鈕后,將對話框中輸入的學號和姓名在它依賴窗口的文本框中顯示。mainText.setText(″學號:″+textl.getText(>+″姓名:″+text2.getText(>>;

setVisible(false>;dispose(>;

}

}

11 / 11

相關文章

相關歷年真題

考試大綱