华南俳烁实业有限公司

自考

各地資訊
當(dāng)前位置:考試網(wǎng) >> 自學(xué)考試 >> 自考真題 >> 工學(xué)類(lèi) >> Java 語(yǔ)言程序設(shè)計(jì)(一) >> 文章內(nèi)容

排行熱點(diǎn)

  • 歷年真題
  • 模擬試題
  • 自考自答

全國(guó)2013年10月自學(xué)考試Java語(yǔ)言程序設(shè)計(jì)(一)試題_第6頁(yè)

來(lái)源:考試網(wǎng) [ 2014年1月6日 ] 【大 中 小】

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

32.閱讀下列程序,請(qǐng)寫(xiě)出該程序的運(yùn)行結(jié)果。

 Class Parent {

   String one,two;

   public Parent(String a,String b){

     one=a;two=b;

   }

   public void print(){

     System.out.println(two+"to"+one);

   }

 }

 public class Child extends Parent{

  public Child(String a,String b){

    super(a,b);

  }

  public void print(){

    System.out.println(one+"to"+two);

  }

  public static void main(String args[]){

    parent p=new Parent("south","north");

    parent t=new Child("east","west");

    p.print();

    t.print();

  }

 }

33.閱讀下列程序,請(qǐng)寫(xiě)出該程序的功能。

 import java.applet.Applet;import java.awt.*;

 public class Test33 extends Applet{

public void paint(Graphics g){

        for(int i=0;i<6;i++)

             drawGraphics(I,g);

    }

    public void drawGraphics(int n,Graphics g){

        g.clearRect(10,10,300,300);

        switch(n){

           case 0:case 3:

               g.setColor(Color.red);

               g.drawRect(50,50,150,150);

               break;

           case 1:case 4:

               g.setColor(Color.blue);

               g.drawOval(40,40,1 60,160);

               break;

           case 2:case5:

               g.setColor(Color.green);

               g.fillRect(50,50,200,200);

               break;

               }

              try{

                Thread.sleep(1500);

              }

             catch(ImerruptedException e){System.exit(0);}

        }

   }

34.閱讀下列程序,請(qǐng)寫(xiě)出該程序的功能。

 import javax.swing.*;  import java.awt.*; import java.awt.event.*;

 public class Test34 {

     public static void main(String[]args){

         ComboBoxDemo myComboBoxGUI = newComboBoxDemo();

     }

 }

 Class ComboBoxDemo extends JFrame implemems ItemListener{

      String CountryList[]={"美國(guó)","中國(guó)","英國(guó)","俄羅斯","韓國(guó)","德國(guó)"};

      im GoldMedalNumber[]={46,38,29,24,13,11};

      JLabel label;JComboBox Combobox;

      Public ComboBoxDemo(){

          setSize(350,150);

          setTitle("第三十屆倫敦奧運(yùn)會(huì)金牌查詢");

          Comainer conPane = getContentPane();

          conPane.setLayout(new FlowLayout());

          combobox=new JComboBox(CountryList);

          combobox.addItemListener(this);

          conPane.add(combobox);

          label=new JLabel();   conPane.add(1abel);   this.setVisible(true);

      }

      public void itemStateChanged(ItemEvem e){

          if(e.getS ource()==combobox)

             label.setText(

               String.valueOf(GoldMedalNumber[combobox.getSelectedIndex()]));

     }

 }

35.閱讀下列程序,請(qǐng)回答下面的問(wèn)題:

 (1)兩個(gè)文本區(qū)內(nèi)分別每次追加何種字符?有多少個(gè)?

 (2)兩個(gè)文本區(qū)里面內(nèi)容的顯示速度有何區(qū)別?

 import iava.awt.*;import java.applet.*;import javax.swing.*;

 public class Test35 extends Applet{

     JTextArea 1Text,rText;

     public void init() {

         setSize(600,500); setLayout(null);

         1Text=new JTextArea();  rText=new JTextArea();

         lText.setFont(new Font ("Times New Roman",1,40));

         rText.setFont(new Font("Modern",1,40));

         JScrollPane jsp1=new JScrollPane(1Text);

         JScrollPane jsp2=new JScrollPane(rText);

         add(jsp1);      add(jsp2);

         jspl.setBounds(20,20,250,450);    jsp2.setBounds(310,20,200,450);

         (new threadl(1Text,"1")).start();    (new threadl(rText,"2")).start();

     }

 }

 class threadl extends Thread{

     protected JTextArea t;

     String text="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

     public thread1(JTextArea text,String m){      super(m);  t=text; }

     public void run()  {

         while(true){

             String S=" ";

             for(int i=0;i<6;i++){

                 int k;

                 if(getName().equals("1"))

                     k=((int)(Math.random()*100)%26);

                 else

                     k=((int)(Math.random()*100)%10)+26;

                 s+=text.charAt(k); //獲取k位置字符

             }

             t.append(s+"\n");

             t.setCaretPosition(t.getText().1ength());//最近輸出的內(nèi)容在文本區(qū)中顯示

             try{sleep(getName().equals("1")?400:700);}

             catch (InterruptedException e){}

         }

    }

 }

36.閱讀下列程序,請(qǐng)寫(xiě)出該程序的功能。

 import java.io.*;

 class Test36{

     public static void main(Stringarg[]){

         int ch;

         try{

            FileReader in=new FileReader(new File("file 1.txt"));

            FileWriter out=new FileWriter(new File("file2.txt"));

            while((ch=in.read())!=-1){

                if(ch>=(int)′A′&&ch<=(int) ′Z′)

                   ch+=32;

                else if(ch>=(int) ′a′&& ch<=(ira) ′z′)

                   ch-=32;

                out.write(ch);

            }

           in.close();             out.close();

        }catch (FileNotFoundException e1){

             System.out.println("文件沒(méi)有找到! "+e1);

        }catch(IOException e2){

             System.out.println("文件讀寫(xiě)出錯(cuò)! "+e2);

        }

        System.out.println("程序結(jié)束! "’);

     }

 }

責(zé)編:may1205
砀山县| 大城县| 泾川县| 铁岭县| 寻乌县| 玉环县| 孙吴县| 耿马| 简阳市| 凭祥市| 鞍山市| 博乐市| 罗田县| 马边| 舒兰市| 安国市| 舞阳县| 五指山市| 旬阳县| 巴彦县| 海林市| 金阳县| 贵德县| 长春市| 寿阳县| 丰原市| 宝鸡市| 县级市| 寻乌县| 烟台市| 太谷县| 西藏| 腾冲县| 瑞安市| 昭觉县| 诸暨市| 宜宾县| 苏尼特左旗| 新兴县| 南木林县| 呼和浩特市|