欧美色欧美亚洲高清在线观看,国产特黄特色a级在线视频,国产一区视频一区欧美,亚洲成a 人在线观看中文

  1. <ul id="fwlom"></ul>

    <object id="fwlom"></object>

    <span id="fwlom"></span><dfn id="fwlom"></dfn>

      <object id="fwlom"></object>

      java實驗4(共5篇)

      時間:2019-05-12 13:05:56下載本文作者:會員上傳
      簡介:寫寫幫文庫小編為你整理了多篇相關(guān)的《java實驗4》,但愿對你工作學(xué)習(xí)有幫助,當(dāng)然你在寫寫幫文庫還可以找到更多《java實驗4》。

      第一篇:java實驗4

      實驗四

      流、文件及基于文本的應(yīng)用

      一、實驗?zāi)康?/p>

      1)理解數(shù)據(jù)流的概念。2)理解Java流的層次結(jié)構(gòu)。3)理解并掌握文件的讀寫操作方法。

      二、實驗內(nèi)容

      1)編寫一個java Application程序,接受用戶輸入的10個整數(shù),比較并輸出其中的最大值和最小值。

      四、實驗原理

      1)字節(jié)流和字符流

      Java的輸入/輸出流中,根據(jù)它們的數(shù)據(jù)類型,主要可分為兩類:字符流(Character Stream)和字節(jié)流(Btye Stream)。(1)字符流

      字符流的輸入/輸出數(shù)據(jù)是字符碼,即Unicode字符。字符流有兩個基本類:Reader類和Writer類。Reader類用于處理字符輸入流,Writer類用于處理字符輸出流。(2)字節(jié)流

      字節(jié)流是按字節(jié)讀/寫二進制數(shù)據(jù)。字節(jié)流有兩個基本的類:InputStream類和OutputStream類。InputStream類用于處理字節(jié)輸入流,OutputStream類用于處理字節(jié)輸出流。2)節(jié)點流和處理流

      按照流是否直接與特定的地方(如磁盤、內(nèi)存等)相連,分為節(jié)點流與處理流。(1)節(jié)點流:可以從或者向一個特定的地方(節(jié)點)讀寫數(shù)據(jù)。如文件流FileReader。(2)處理流:是對一個已經(jīng)存在的流的連接和封裝,通過所封裝的流的功能調(diào)用實現(xiàn)數(shù)據(jù)讀、寫功能。處理流也稱過濾流,如緩沖處理流BufferedReader。

      3)文件字節(jié)流

      (1)文件字節(jié)輸入流

      FileInputStream(文件字節(jié)輸入流)主要用于文件的輸入,通過該類創(chuàng)建的對象可以從文件中讀數(shù)據(jù)。FileInputStream類提供的常用方法有:

      FileInputStream(String name)throws FileNotFoundException 創(chuàng)建一個關(guān)聯(lián)到實際文件的文件字節(jié)輸入流,name指定了要關(guān)聯(lián)到的文件的路徑名。如果該文件不存在或是不能被打開,將拋出一個FileNotFoundException異常。FileInputStream(File file)throws FileNotFoundException 創(chuàng)建一個關(guān)聯(lián)到實際文件的文件字節(jié)輸入流,file是一個文件對象。如果該文件不存在或是不能被打開,將拋出一個FileNotFoundException異常(2)文件字節(jié)輸出流

      FileOutputStream(文件字節(jié)輸出流)主要用于文件的輸出,通過該類創(chuàng)建的對象可以往文件中寫數(shù)據(jù)。FileOutputStream類提供的常用方法有: FileOutputStream(String name)throws FileNotFoundException FileOutputStream(File file)throws FileNotFoundException FileOutputStream(String name, boolean append)throws FileNotFoundException FileOutputStream(File file, boolean append)throws FileNotFoundException 4)字符文件流

      FileReader用于文件的輸入,該類以字符流的方式從文件中讀數(shù)據(jù)。FileReader類提供的常用方法有:

      FileReader(String name)throws FileNotFoundException FileReader(File file)throws FileNotFoundException FileWriter用于文件的輸出,該類以字符流的方式往文件中寫數(shù)據(jù)。FileWriter類提供的常用方法有:

      FileWriter(String name)throws FileNotFoundException FileWriter(String name, boolean append)throws FileNotFoundException FileWriter(File file, boolean append)throws FileNotFoundException 5)Java Application命令行參數(shù)

      Java Application是用命令行來啟動執(zhí)行的,命令行參數(shù)就成為向java application傳入數(shù)據(jù)的常用方式。在啟動java應(yīng)用程序時可以一次性的向應(yīng)用程序中傳遞0到多個參數(shù)。格式為: java 類名 參數(shù)1 參數(shù)2 …

      參數(shù)間用空格隔開,如果參數(shù)本身有空格,則要用一對雙引號引起來。命令行參數(shù)被系

      統(tǒng)以String數(shù)組的方式傳遞給main方法,由參數(shù)args接收。

      六、思考題

      1)從一個文本文件Student.txt中讀入30個學(xué)生的姓名、專業(yè)、班級、java成績,并實現(xiàn)如下功能

      (1)顯示所有學(xué)生的成績信息;

      (2)統(tǒng)計各個班級的最高分、最低分和平均分,并將結(jié)果寫入另外一個文件StudentTj.txt;

      (3)將所有學(xué)生信息寫入Access數(shù)據(jù)庫,數(shù)據(jù)庫自己建立。(可選)源程序:

      import java.io.*;import java.util.*;public class MaxMinClass {

      } static int maxint(int data[],int n){

      {

      }

      return h;static int minint(int data[],int n){

      {

      if(data[i]

      {

      }

      h=i;int h=0;

      for(int i=0;i

      if(data[i]>data[h])

      {

      }

      h=i;int h=0;

      for(int i=0;i

      }

      }

      return h;public static void main(String args[]){

      } String s=“";int i=0;int data[]=new int[10];System.out.println(”請輸入10個整數(shù),以空格作為分隔符:“);try {

      } catch(IOException e){ } System.out.println(”你已經(jīng)輸入的10個整數(shù)為:“+s);StringTokenizer st=new StringTokenizer(s);while(st.hasMoreTokens()){

      } System.out.println(”十個數(shù)中的最大的數(shù)為:“+data[maxint(data,10)]);System.out.println(”十個數(shù)中的最大的數(shù)為:“+data[minint(data,10)]);data[i]=Integer.parseInt(st.nextToken());i++;BufferedReader in=new BufferedReader(new InputStreamReader(System.in));s=in.readLine();

      }

      import java.io.*;import java.util.*;class MaxMinClass {

      }

      }

      static float average(float data[],int n){

      {

      h+=data[i];

      } float h=0;

      for(int i=0;i

      {

      }

      return h;

      if(data[i]

      {

      }

      h=i;int h=0;

      for(int i=0;i

      int maxint(float data[],int n){

      {

      }

      return h;

      if(data[i]>data[h])

      {

      }

      h=i;int h=0;

      for(int i=0;i

      h=h/n;

      } class Student {

      } public class TestFile {

      static String ToString(float a,float b,float c){

      } public static void main(String args[])throws Exception { File f=new File(”F:Student.txt“);String data[]=new String[30];Student s[]=new Student[30];BufferedReader in=new BufferedReader(new InputStreamReader(new FileInputStream(f)));for(int i=0;i<30;i++)

      { data[i]=in.readLine();// System.out.println(data[i]);return ”最高分為“+a+”

      最低分為“+b+”

      平均分為“+c+”rn“;String name;String zhuanye;String banji;float

      chenji;Student(String name,String zhuanye,String banji,float chenji){

      } public String toString(){

      } return ”姓名:“+this.name+”

      專業(yè):“+this.zhuanye+”

      班級:“+this.banji+”

      成績: this.name=name;this.zhuanye=zhuanye;this.banji=banji;this.chenji=chenji;

      return h;}

      “+this.chenji;

      } in.close();for(int i=0;i<30;i++)

      { StringTokenizer st=new StringTokenizer(data[i]);

      //

      System.out.println(st.countTokens());

      s[i]=new

      } int m=0,n=0,q=0;float data1[]=new float[20];float data2[]=new float[20];float data3[]=new float[20];for(int i=0;i<30;i++){

      } System.out.println(”班級01班的最高分:“+data1[MaxMinClass.maxint(data1,n)]);System.out.println(”班級01班的最低分:“+data1[MaxMinClass.minint(data1,n)]);System.out.println(”班級01班的平均分:“+MaxMinClass.average(data1, n));System.out.println(”班級02班的最高分:“+data2[MaxMinClass.maxint(data2,m)]);System.out.println(”班級02班的最低分:“+data2[MaxMinClass.minint(data2,m)]);System.out.println(”班級02班的平均分:“+MaxMinClass.average(data2, m));System.out.println(”班級03班的最高分:“+data3[MaxMinClass.maxint(data3,q)]);System.out.println(”班級03班的最低分:“+data3[MaxMinClass.minint(data3,q)]);System.out.println(”班級03班的平均分:“+MaxMinClass.average(data3, q));if(s[i].banji.equalsIgnoreCase(”01“)){

      } if(s[i].banji.equalsIgnoreCase(”02“)){

      } if(s[i].banji.equalsIgnoreCase(”03“)){

      } data3[q]=s[i].chenji;q++;data2[m]=s[i].chenji;m++;data1[n]=s[i].chenji;n++;

      System.out.println(s[i]);Student(st.nextToken(),st.nextToken(),st.nextToken(),Integer.parseInt(st.nextToken()));

      } FileOutputStream fos=new FileOutputStream(”F:StudentTj.txt“);BufferedOutputStream bos=new BufferedOutputStream(fos);bos.write(”班級01班:“.getBytes());String sa=ToString(data1[MaxMinClass.maxint(data1,n)],data1[MaxMinClass.minint bos.write(sa.getBytes());

      bos.write(”班級02班:“.getBytes());String sa1=ToString(data2[MaxMinClass.maxint(data2,m)],data2[MaxMinClass.minint bos.write(sa1.getBytes());

      bos.write(”班級03班:".getBytes());String sa2=ToString(data3[MaxMinClass.maxint(data3,q)],data3[MaxMinClass.minint bos.write(sa2.getBytes());bos.close();}(data1,n)],MaxMinClass.average(data1, n));(data2,m)],MaxMinClass.average(data2, m));(data3,q)],MaxMinClass.average(data3, q));

      第二篇:java上機實驗

      1、實驗一:多線程程序設(shè)計:炮打飛機

      實驗?zāi)康模簩W(xué)會使用多線程進行并發(fā)程序設(shè)計

      實驗內(nèi)容:編寫一個應(yīng)用程序模擬大炮打飛機。在GUI界面上,飛機水平飛行,用界面上的按鈕控制大炮的運行方向(如向左,向右,向上,向下)。當(dāng)炮彈碰著飛機后,飛機墜落。

      2、實驗二:數(shù)據(jù)庫編程:書目信息管理

      實驗?zāi)康模赫莆諗?shù)據(jù)庫編程技術(shù)。能正確連接數(shù)據(jù)庫,能對數(shù)據(jù)庫中信息進行查詢、插

      入、刪除、修改。

      實驗內(nèi)容:在數(shù)據(jù)庫中創(chuàng)建一張書目信息表,包括書名、作者、出版社、出版日期、書

      號、價格字段。設(shè)計一個GUI界面進行書目管理。在該界面上有四個選項卡,分別是查詢、插入、刪除、修改。點擊查詢選項卡,出現(xiàn)的界面上有書名、作者、出版社、書號四個文本框,一個按鈕和一個只讀文本區(qū)。文本框內(nèi)容可以為空,輸入相應(yīng)的查詢信息后(例如根據(jù)書名查詢可以僅輸入書名),點擊界面上的“查詢”按鈕,可以在界面下方的文本區(qū)中顯示出符合條件的書目詳細信息。點擊插入選項卡,出現(xiàn)的界面上有書名、作者、出版社、出版日期、書號、價格文本框,一個按鈕。在文本框中輸入信息后,點擊“插入”按鈕,該書目信息插入數(shù)據(jù)庫表中。點擊刪除選項卡,出現(xiàn)的界面上有書名文本框和一個按鈕,輸入書名后點擊“刪除”按鈕,該書目信息從數(shù)據(jù)庫表中刪除。點擊修改選項卡,出現(xiàn)的界面上有書名、作者、出版社、出版日期、書號、價格文本框,一個按鈕。輸入的書名必須是已存在的,否則會彈出消息框顯示出錯信息。輸入信息后,點擊“修改”按鈕,數(shù)據(jù)庫表中的相應(yīng)書目信息被修改為新值。

      3、實驗三:Applet編程:鴨子的移動

      實驗?zāi)康模赫莆誂pplet程序設(shè)計的方法,學(xué)會在Applet中繪制圖片,能采用雙緩沖技術(shù)進行圖片繪制,會在Applet中采用多線程進行動畫顯示。能在Applet中實現(xiàn)動畫的平滑顯示,避免閃爍現(xiàn)象。

      實驗內(nèi)容:在Applet窗口中顯示一只鴨子圖片,要求這只鴨子以每秒100幀的速率水平移動,移到窗口邊界再返回移動。在窗口中點擊鼠標(biāo),鴨子停止移動;再次點擊鼠標(biāo),鴨子恢復(fù)移動。

      4、實驗四:網(wǎng)絡(luò)編程:聊天室的實現(xiàn)

      實驗?zāi)康模簳帉懣蛻舳撕头?wù)器程序?qū)崿F(xiàn)C/S模式下的通信,會使用多線程進行網(wǎng)絡(luò)編程。

      實驗內(nèi)容:編寫一個聊天室程序:客戶端界面請自行設(shè)計,可使其具有個性化特征; 可在實現(xiàn)基本的聊天室功能的基礎(chǔ)上添加個性化的功能。

      第三篇:JAVA實驗指導(dǎo)書

      實驗

      一、簡單Java程序設(shè)計

      一、實驗?zāi)康?/p>

      1. 學(xué)習(xí)使用JCreator開發(fā)JAVA代碼。

      2. 了解JAVA的運行環(huán)境,掌握開發(fā)JAVA代碼所需要的相關(guān)配置。3. 在JCreator中輸入習(xí)題程序,驗證程序的正確性,熟悉開發(fā)環(huán)境。

      二、實驗內(nèi)容

      1. 設(shè)置實驗環(huán)境

      a.安裝JDK,下載JDK包以后,按安裝向?qū)У奶崾疽来伟惭b,可直接安裝在C盤根目錄下。

      b.更新環(huán)境變量:

      2. 編寫程序:由鍵盤輸入兩個字符串“12”與“24”,將它們轉(zhuǎn)換成整數(shù),然后計算并輸出這兩個數(shù)的和。

      3. 編寫程序:由鍵盤輸入給出一個百分制成績,要求輸出成績等級’A’、’B’、’C’和’D’,90分以上為’A’,75~89為’B’,60~74為’C’,60分以下為’D’。

      4. 編一程序,求一個10項所組成的等差數(shù)列,其奇數(shù)項之和為135,偶數(shù)項之和為150。5. 用for語句輸出下列數(shù)字金字塔:

      1 3 1 1 3 5 3 1 3 5 7 5 3 1 1 3 5 7 9 7 5 3 1 6. 編寫程序:由鍵盤輸入一正整數(shù),求出小于且等于這個數(shù)的所有質(zhì)數(shù)。實驗

      二、基本數(shù)據(jù)類型和數(shù)組

      一、實驗?zāi)康?/p>

      1.進一步熟悉JCreator開發(fā)JAVA代碼。

      2.了解數(shù)組的使用與JAVA中對字符串的主要操作。

      3.在JCreator中輸入習(xí)題程序,驗證程序的正確性,熟悉開發(fā)環(huán)境。

      二、實驗內(nèi)容

      1.編寫程序:由鍵盤輸入一整數(shù),求出該數(shù)所有的因子,如輸入6,則輸出的6的所有因子為1、2、3、6。

      2假設(shè)有一條鋼材長2000米,每天截取其中的一半,編一程序求出多少天后,鋼材的長度開始短于5米?

      3編寫程序:利用數(shù)列4?(1?13?15?17?19?111??)來取得?的近似值。并計算在得到3.14159之前,這個數(shù)列要取到第幾項?

      4使用java.long.Math類,生成10個0~99之間的隨機整數(shù),求出它們中的最大值和最小值。

      提示:java.long.Math類支持random方法:Math.Random()。該方法返回值是正數(shù),類型為double,范圍為0~1。如果要得到其它范圍的數(shù),則要進行相應(yīng)的轉(zhuǎn)換。例如要得到(a,b)之間的整數(shù)的方法是:(int)((b-a+1)*Math.random()+a)。若要得到(0,99)之間的整數(shù)可以使用下列語句:

      int m =(int)(100*Math.random());5編寫程序:聲明一數(shù)組來存放12個月的英文名稱,由用戶從鍵盤輸入月份,如輸入8,則程序輸出相應(yīng)的月份名稱:August。同時請大家考慮若是用戶輸入了1~12以外的內(nèi)容,你的程序?qū)⑷绾螒?yīng)對?

      6編寫程序:由鍵盤輸入一16位的長整數(shù),統(tǒng)計0~9這十個數(shù)字每一個出現(xiàn)的次數(shù)。7編寫程序:將兩個各有6個整數(shù)的數(shù)組,合并成一個由小至大排列的數(shù)組(該數(shù)組的長度為12)。8編寫程序:以遞歸的方式實現(xiàn)1+2+3+??+n(n = 200)的計算。

      實驗

      三、類與對象

      一、實驗?zāi)康?/p>

      1.進一步熟悉JCreator開發(fā)JAVA代碼。2.了解類和對象之間的關(guān)系。

      3.在JCreator中聲明一個類,其中有多個構(gòu)造方法。用不同的構(gòu)造方法創(chuàng)建對象。

      二、實驗內(nèi)容 聲明一個矩形類Rectangle,其中有多個構(gòu)造方法。用不同的構(gòu)造方法創(chuàng)建對象,并輸出矩形的周長和面積。聲明一個矩陣類Matrix,有這樣一些實例方法:將一個矩陣轉(zhuǎn)置、求兩個矩陣的和。寫出下面程序的運行結(jié)果

      class University { String name, city;University(String name, String city){ this.name = name;this.city = city;System.out.println(“super class”);} boolean samecity(String city){ if(city.equals(this.city))return true;else return false;} boolean samecity(University u){ return samecity(u.city);} }

      class UniversityWorld extends University { String country;UniversityWorld(String name, String city, String country){ super(name,city);this.country = country;System.out.println(“sub class”);} boolean samecity(String city, String country){ if(city.equals(this.city)&& country.equals(this.country))return true;else return false;} boolean samecity(UniversityWorld other){ return samecity(other.city, other.country);} }

      class UniversityWorldCity { public static void main(String args[]){ String city = “上?!?country = “中 國”;UniversityWorld u1 =new UniversityWorld(“北京大學(xué)”, “北京”, “中 國”);UniversityWorld u2 = new UniversityWorld(“清 華 大 學(xué)”, “北京”, “中 國”);System.out.println(“u1 = ” + u1.name + “, ” + u1.city + “, ” +u1.country);System.out.println(“u2 = ” + u2.name + “, ” + u2.city+ “,” + u2.country);System.out.println(“city = ” + city + “, country = ” +country);System.out.println(“u1.samecity(u2)= ” + u1.samecity(u2));System.out.println(“u1.samecity(city, country)= ” + u1.samecity(city,country));} } 實驗

      四、繼承與接口

      一、實驗?zāi)康?/p>

      1.進一步熟悉JCreator開發(fā)JAVA代碼。2.了解類的成員的訪問權(quán)限和包的關(guān)系。

      3.了解繼承和接口的區(qū)別已及它們各自的作用,熟悉開發(fā)環(huán)境。

      二、實驗內(nèi)容 創(chuàng)建兩個String類的對象str1和str2,判斷sr2是否是str1的子串。如果是,輸出str1中,在子串ztr2前和后的字符串。如:

      “Action”是“addActionListener”的子串,在此子串前是字符串”add”,后面是字符串”Listener”。寫出下面程序的運行結(jié)果 class Leve1{ String name=“";

      int height,width;public Leve1(){;}

      public Leve1(Leve1 le){

      name=le.name;

      height=le.height;

      width=le.width;} public Leve1(String na,int h,int w){

      name=na;

      height=h;

      width=w;}

      public int higherthen(Leve1 t){

      return this.height-t.height;}

      public void print(){

      System.out.println(”class Leve1: “);

      System.out.println(”Name=: “+name+”, Height=: “+height+”, Width=: “+width);} } class Leve2 extends Leve1{ int width;

      public Leve2(){;}

      public Leve2(Leve1 le,int h,int w){

      super(le);

      height=h;

      width=w;}

      public int widerthen(){

      return width-super.width;} public void print(){

      System.out.println(”class Leve2: “);

      System.out.println(”Name=: “+name+”, Height=: “+height+”, Width=: “+width);} } public class Lev_ex{ public static void main(String args[]){ Leve1 le1=new Leve1(”Tower_1“,50,20);

      Leve2 le2=new Leve2(le1,40,25);

      le1.print();

      le2.print();

      System.out.println(”Leve1 is “+le1.higherthen(le2)+” highter then Leve2.“);

      System.out.println(”Leve2 is “+le2.widerthen()+” wider then Leve1.“);} }

      3、編寫代碼,完成功能:建立一個窗口,窗口上方橫列“文件”、“選項”兩個菜單項。其中“文件”菜單下隱含“退出”、“顯示”、“隱藏”三個子菜單,每個子菜單都可用快捷鍵選擇并且“退出”與其他兩個子菜單之間用分隔線分隔?!斑x項”菜單下包含名稱為“1”、“2”、“3”。。。“50”的50個菜單項,當(dāng)選擇其中任何一個數(shù)字選項時,窗口正中將顯示0至該數(shù)字之間所有數(shù)的平方和(包含數(shù)字本身)。如選中選項“3”,則顯示14(SUM=1*1+2*2+3*3=14)。實驗

      五、常用實用類

      一、實驗?zāi)康?/p>

      1.進一步熟悉JCreator開發(fā)JAVA代碼。2.了解常用實用類的使用。

      二、實驗內(nèi)容 求和工具。編寫一個程序:設(shè)計如下面圖示的界面。在該界面中,可以在第一個文本框中輸入第一個加數(shù),可以在第二個文本框中輸入第二個加數(shù),當(dāng)用鼠標(biāo)的左鍵單擊按鈕”="時,在第三個文本框中顯示出前面兩個加數(shù)之和。設(shè)計一個簡單的計算器,能進行兩個數(shù)的加、減、乘、除。界面如圖所示?!癱lear”按鈕用于清理文本域的內(nèi)容。16方格排序游戲設(shè)計。編寫一個程序:如圖所示,要求在界面上設(shè)計4×4的按鈕,即16個按鈕排列成4×4的網(wǎng)格形狀。其中有且只有15個按鈕上有從1到15的數(shù)字,而且這些數(shù)字在按鈕上不重復(fù)出現(xiàn)。另外有一個按鈕上沒有數(shù)字。當(dāng)程序剛啟動時這15個數(shù)字是隨機排列的。當(dāng)用鼠標(biāo)左鍵單擊某個按鈕,如果該按鈕上有數(shù)字而且該按鈕在沒有數(shù)字的按鈕的邊上,則將該按鈕上的數(shù)字給沒有數(shù)字的按鈕,同時該按鈕就變成了沒有數(shù)字的按鈕。當(dāng)15個數(shù)字在4×4的網(wǎng)格中呈順序或逆序排列,則顯示消息框表明排列成功,并重新隨機排列這15個數(shù)字在按鈕網(wǎng)格上的位置。(提示: Math.random()可以產(chǎn)生隨機數(shù))

      實驗

      六、GUI編程

      一、實驗?zāi)康?/p>

      1.進一步熟悉JCreator開發(fā)JAVA代碼。2.了解GUI編程。

      二、實驗內(nèi)容

      1. 在下拉列表choice1中選擇整數(shù)N,單擊“生成”按鈕在列表框List1和List2中顯示N對的隨機數(shù)(2~1000),在列表框List3中顯示每對隨機數(shù)的最大公約數(shù)。單擊“排序”按鈕,List3中的N個最大公約數(shù)按從小到大排列。(提示:排序算法采用冒泡法。兩數(shù)的最大公約數(shù)可以采用歐幾里得算法:不斷用兩數(shù)中較大數(shù)減較小的數(shù),至到有一個數(shù)等于0。另外一個大于0的數(shù)就是這兩數(shù)的最大公數(shù)約)。

      2.完成程序?qū)崿F(xiàn)一個簡單的文本編輯器,其中File菜單實現(xiàn)Exit子菜單,Edit菜單實現(xiàn)Copy、Cut、Paste、DeleteAll功能,Option菜單實現(xiàn)字體設(shè)置功能。

      3.在文本框中輸入函數(shù)y=sin(ax)中a的值,點擊draw按鈕畫出函數(shù)圖形。

      實驗

      七、多線程

      一、實驗?zāi)康?/p>

      1.進一步熟悉JCreator開發(fā)JAVA代碼。2.了解多線程編程。

      二、實驗內(nèi)容

      1、編寫程序,有兩個線程,分別在屏幕上顯示1~50之間的奇數(shù)和偶數(shù)。觀察一共有幾個線程在運行,各個線程是怎樣被處理器執(zhí)行的。

      2、編寫一個程序,創(chuàng)建兩個線程,其中一個產(chǎn)生5個1~100之間的隨機整數(shù),另一個線程將這5個數(shù)加起來。觀察運行的情況,分析是否正確。如果結(jié)果有問題,想辦法解決它。

      實驗

      八、圖形圖像

      一、實驗?zāi)康?/p>

      1.進一步熟悉JCreator開發(fā)JAVA代碼。2.了解圖形圖像編程。

      二、實驗內(nèi)容

      1、編寫一個模擬畫圖的程序,用戶可以選擇繪圖的圖形,如“線”、“矩形”、“圓”、“橢圓”等,選擇后即可在屏幕上移動鼠標(biāo)畫圖。(提示:選擇圖形可以使用單選按鈕組,畫圖需要處理鼠標(biāo)事件。)

      第四篇:Java程序設(shè)計實驗2

      學(xué) 生 實 驗 報 告 冊

      課程名稱:

      學(xué)生學(xué)號:

      所屬院部:

      (理工類)

      專業(yè)班級:

      學(xué)生姓名:

      指導(dǎo)教師: ——20 學(xué)年 第 學(xué)期

      金陵科技學(xué)院教務(wù)處制

      實驗報告書寫要求

      實驗報告原則上要求學(xué)生手寫,要求書寫工整。若因課程特點需打印的,標(biāo)題采用四號黑體,正文采用小四號宋體,單倍行距。紙張一律采用A4的紙張。

      實驗報告書寫說明

      實驗報告中實驗?zāi)康暮鸵?、實驗儀器和設(shè)備、實驗內(nèi)容與過程、實驗結(jié)果與分析這四項內(nèi)容為必需項。教師可根據(jù)學(xué)科特點和實驗具體要求增加項目。

      填寫注意事項

      (1)細致觀察,及時、準(zhǔn)確、如實記錄。(2)準(zhǔn)確說明,層次清晰。

      (3)盡量采用專用術(shù)語來說明事物。

      (4)外文、符號、公式要準(zhǔn)確,應(yīng)使用統(tǒng)一規(guī)定的名詞和符號。(5)應(yīng)獨立完成實驗報告的書寫,嚴禁抄襲、復(fù)印,一經(jīng)發(fā)現(xiàn),以零分論處。

      實驗報告批改說明

      實驗報告的批改要及時、認真、仔細,一律用紅色筆批改。實驗報告的批改成績采用五級記分制或百分制,按《金陵科技學(xué)院課堂教學(xué)實施細則》中作業(yè)批閱成績評定要求執(zhí)行。

      實驗報告裝訂要求

      實驗批改完畢后,任課老師將每門課程的每個實驗項目的實驗報告以自然班為單位、按學(xué)號升序排列,裝訂成冊,并附上一份該門課程的實驗大綱。

      金陵科技學(xué)院實驗報告

      實驗項目名稱: 面向?qū)ο缶幊虒嶒?實驗學(xué)時: 8 同組學(xué)生姓名: 實驗地點: 實驗日期: 實驗成績: 批改教師: 批改時間:

      金陵科技學(xué)院實驗報告

      實驗1 面向?qū)ο缶幊虒嶒?/p>

      一、實驗?zāi)康暮鸵?/p>

      (1)理解Java概念、掌握JDK環(huán)境配置(2)熟悉Java開發(fā)過程

      (3)掌握Java面向?qū)ο缶幊袒A(chǔ):封裝、繼承、多態(tài)(4)掌握Java接口編程,理解開發(fā)模式

      二、實驗儀器和設(shè)備

      奔騰以上個人計算機,windows操作系統(tǒng)。

      配置好JDK環(huán)境,安裝集成開發(fā)環(huán)境(Eclipse)

      三、實驗內(nèi)容與過程

      1、JDK環(huán)境配置

      2、面向?qū)ο蟮姆庋b性

      范例:設(shè)計一個表示學(xué)生的類,里面有學(xué)生的三項成績:計算機成績、數(shù)學(xué)成績、英語成績。要求可以求總分、平均分、最高分、最低分,并且可以輸出一個學(xué)生的完整信息。代碼如下: class Student{ private String name;private int age;private float english;private float computer;private float math;public Student(){} public Student(String n,int a,float e,float c,float m){

      this.setName(n);

      this.setAge(a);

      this.setEnglish(e);

      this.setComputer(c);

      this.setMath(m);} public float sum(){

      return english + computer + math;} public float avg(){

      return this.sum()/ 3;} public float max(){

      float max = computer>math?computer:math;

      max = max>english?max:english;

      return max;} public float min(){

      float min = computer

      min = min

      return min;

      金陵科技學(xué)院實驗報告

      } public String getInfo(){

      return “學(xué)生信息: n” +

      “t|-姓名:” + this.getName()+ “n” +

      “t|-年齡:” + this.getAge()+ “n” +

      “t|-數(shù)學(xué)成績:” + this.getMath()+ “n” +

      “t|-英語成績:” + this.getEnglish()+ “n” +

      “t|-計算機成績:” + this.getComputer();} public void setName(String n){

      name = n;} public void setAge(int a){

      age = a;} public void setEnglish(float e){

      english = e;} public void setComputer(float c){

      computer = c;} public void setMath(float m){

      math = m;} public String getName(){

      return name;} public int getAge(){

      return age;} public float getEnglish(){

      return english;} public float getComputer(){

      return computer;} public float getMath(){

      return math;} } public class ExecDemo{ public static void main(String args[]){

      Student stu = new Student(“張三”,30,89.0f,91.0f,87.0f);

      System.out.println(“總分:” + stu.sum());

      金陵科技學(xué)院實驗報告

      }

      } System.out.println(“平均分:” + stu.avg());System.out.println(“最高分:” + stu.max());System.out.println(“最低分:” + stu.min());System.out.println(stu.getInfo());對照范例寫出如下題目:

      (1)編寫并測試一個代表地址的Address類,包括以下的屬性:國家、省份、城市、街道、郵編。

      可以從此地址類中得到一個完整的地址信息。

      (2)定義并測試一個代表員工的Employee類。它的屬性包括“員工姓名”、“員工號碼”、“員工基本薪水”,它的方法包括“構(gòu)造方法”、“獲取員工姓名”、“獲取員工號碼”、“獲取員工基本薪水”、“設(shè)置員工姓名”、“設(shè)置員工號碼”、“設(shè)置員工基本薪水”、所有員工信息的輸出getInfo。(3)、定義一個圓形類,可以返回圓的面積與周長。

      class Circle{

      成員變量 半徑 r

      構(gòu)造方法

      成員函數(shù) 設(shè)置和獲取 半徑

      計算周長

      計算面積

      所有信息輸出 } 定義一個矩形類,返回矩形的面積與周長(4)、思考設(shè)計:一個人有一本書,一本書屬于一個人。//一個人有一本書,一本書屬于一個人 //類 新的類別、類型 定義新的數(shù)據(jù)類型 //兩個類的關(guān)系 獨立的兩個類 使用 class Person{ private String name;private int age;private Book book;//一個人有一本書 public Person(){

      } public Person(String name,int age){ this.name=name;this.age=age;} public void setBook(Book book){ this.book=book;} public Book getBook(){ return this.book;

      金陵科技學(xué)院實驗報告

      } } class Book{ private String name;private float price;private Person person;//一本書屬于一個人 public Book(){ } public Book(String name,float price){ this.name=name;this.price=price;} public void setPerson(Person person){ this.person=person;} public Person getPerson(){ return this.person;} } public class TestBP{ public static void main(String args[]){ Person per=new Person(“zhangsan”,20);Book bok=new Book(“Java program”,20.0f);per.setBook(bok);//一個人有一本書

      bok.setPerson(per);//一本書屬于一個人

      per.getBook().getPrice();bok.getPerson().getName();} }

      3、面向?qū)ο蟮睦^承性

      范例:要求定義一個數(shù)組類Array,里面定義了一個整型數(shù)組,但是此整型數(shù)組屬于動態(tài)分配大小,即:所有的大小由程序指定,并在此基礎(chǔ)上實現(xiàn)以下的兩個子類:

      反轉(zhuǎn)類:可以將數(shù)組的內(nèi)容反轉(zhuǎn)排列

      排序類:可以對數(shù)組進行排序的操作 class Array{ private int temp[] = null;// 只是聲明數(shù)組,但是大小未知

      private int foot = 0;// 用于保存下一個的記錄點

      public Array(int len){

      if(len>0){

      this.temp = new int[len];// 此時大小由外部決定

      }else{

      this.temp = new int[1];// 至少開辟一個空間

      } }

      金陵科技學(xué)院實驗報告

      public boolean add(int i){ // 加入數(shù)據(jù)操作

      if(this.foot

      this.temp[this.foot] = i;// 加入內(nèi)容

      this.foot++;// 改變長度

      return true;// 加入成功返回true

      }else{

      return false;// 加入失敗

      } } public int[] getArray(){ // 返回全部的數(shù)組

      return this.temp;} } class SortArray extends Array{ public SortArray(int len){

      super(len);} public int[] getArray(){

      java.util.Arrays.sort(super.getArray());// 排序操作

      return super.getArray();// 返回的是排序后的內(nèi)容

      } } class ReverseArray extends Array{ public ReverseArray(int len){

      super(len);} public int[] getArray(){

      int rt[] = new int[super.getArray().length];// 根據(jù)大小開辟新數(shù)組

      int count = rt.length-1;

      for(int x=0;x

      rt[count] = super.getArray()[x];

      count--;

      }

      return rt;} } public class ArrayDemo{ public static void main(String args[]){

      ReverseArray arr = new ReverseArray(6);

      System.out.println(arr.add(3));

      System.out.println(arr.add(23));

      System.out.println(arr.add(1));

      System.out.println(arr.add(5));

      金陵科技學(xué)院實驗報告

      System.out.println(arr.add(6));

      System.out.println(arr.add(8));

      System.out.println(arr.add(11));

      System.out.println(arr.add(16));

      print(arr.getArray());} public static void print(int i[]){

      for(int x=0;x

      System.out.print(i[x] + “、”);

      } } } 對照范例寫出如下題目:

      (1).創(chuàng)建GrandFather類,其中包括

      a)屬性:姓名(name),年齡(age)

      b)方法getGrandFather():顯示爺爺?shù)男畔?/p>

      c)構(gòu)造方法:給爺爺?shù)男彰?,年齡賦值(2).創(chuàng)建Father類,繼承Grandfather類 a)屬性:除了繼承爺爺?shù)膶傩砸酝?,還要增加自己的屬性:“職業(yè)”(occupation)b)構(gòu)造方法:顯式調(diào)用父類的構(gòu)造方法,為Father類的姓名和年齡賦初始值。再為職業(yè)輸入初始值。

      c)方法getFather(): 顯示父親的相關(guān)信息

      (3).創(chuàng)建ClassMain()類,定義main()方法,構(gòu)造GrandFather類的對象和Father類的對象,并分別顯示詳細信息。

      3、面向?qū)ο蠖鄳B(tài)性

      范例:計算柱體的體積。柱體體積計算公式是:底部面積乘以高度 柱體底部分為 圓形和矩形 要求:通過抽象類和多態(tài)實現(xiàn) package cn.jit.demo;abstract class Bottom { //父類抽象類 底部

      public abstract double calculatorArea();} class CircleBottom extends Bottom{ //圓形底

      /** * 半徑

      */ private double radius;

      @Override public double calculatorArea(){

      return Math.PI * radius * radius;} public double getRadius(){

      金陵科技學(xué)院實驗報告

      return radius;} public void setRadius(double radius){

      this.radius = radius;} public CircleBottom(double radius){

      super();

      this.radius = radius;} } class SquareBottom extends Bottom{ //矩形底

      private double sideA;

      private double sideB;public double getSideA(){

      return sideA;} public void setSideA(double sideA){

      this.sideA = sideA;} public double getSideB(){

      return sideB;} public void setSideB(double sideB){

      this.sideB = sideB;} @Override public double calculatorArea(){

      return sideA * sideB;} public SquareBottom(double sideA, double sideB){

      super();

      this.sideA = sideA;

      this.sideB = sideB;} } class ZhuTi { //柱體類,完成形狀的拼裝

      /** * 底

      */ private Bottom bottom;/** * 高

      */

      金陵科技學(xué)院實驗報告

      private double height;/** * 計算體積

      * @return */ public double calculatorVolumn(){

      return bottom.calculatorArea()* height;} public ZhuTi(Bottom bottom, double height){

      super();

      this.bottom = bottom;

      this.height = height;} public Bottom getBottom(){

      return bottom;} public void setBottom(Bottom bottom){

      this.bottom = bottom;} public double getHeight(){

      return height;} public void setHeight(double height){

      this.height = height;} public void changeBottom(Bottom bottom){

      this.bottom = bottom;} } public class VolumnTest { //測試類

      public static void main(String[] args){

      Bottom bottom = new CircleBottom(1.0);

      double height = 1.0;

      ZhuTi zhuTi = new ZhuTi(bottom,height);

      double result = zhuTi.calculatorVolumn();

      System.out.println(“圓柱體的體積是:” + result);

      bottom = new SquareBottom(1.0,1.0);

      zhuTi.changeBottom(bottom);

      result = zhuTi.calculatorVolumn();

      System.out.println(“立方體的體積是:” + result);} } 范例:接口和多態(tài)的應(yīng)用,例如:電腦上實現(xiàn)了USB接口,U盤,打印機等等也都實現(xiàn)了此標(biāo)準(zhǔn)。

      金陵科技學(xué)院實驗報告

      interface USB{ public void start();// 開始工作

      public void stop();// 結(jié)束工作 } class Computer{ public static void plugin(USB usb){

      usb.start();

      usb.stop();} };class Flash implements USB{ public void start(){

      System.out.println(“U盤開始工作。”);} public void stop(){

      System.out.println(“U盤停止工作?!?;} };class Print implements USB{ public void start(){

      System.out.println(“打印機開始工作?!?;} public void stop(){

      System.out.println(“打印機停止工作?!?;} };public class InterPolDemo02{ public static void main(String args[]){

      Computer.plugin(new Flash());

      Computer.plugin(new Print());} };對照范例,寫出以下程序:(1)樂器(Instrument)的標(biāo)準(zhǔn)為彈奏(play),而樂器類型分為:鋼琴(Piano)和小提琴(Violin),各種樂器的彈奏方法各不同。編寫代碼實現(xiàn)不同樂器的彈奏。(2)計算機模擬

      四、實驗結(jié)果與分析(程序運行結(jié)果及其分析)

      五、實驗體會

      金陵科技學(xué)院實驗報告

      實驗項目名稱: 類集

      實驗學(xué)時: 4 同組學(xué)生姓名: 實驗地點: 實驗日期: 實驗成績: 批改教師: 批改時間:

      金陵科技學(xué)院實驗報告

      實驗2 類集

      一、實驗?zāi)康暮鸵螅?)理解類集概念

      (2)熟悉Collection接口、List接口、Set接口和Map接口(3)掌握ArrayList類、HashSet類和TreeSet類(4)理解TreeMap、HashMap

      二、實驗儀器和設(shè)備

      奔騰以上個人計算機,windows操作系統(tǒng)。

      配置好JDK環(huán)境,安裝集成開發(fā)環(huán)境(Eclipse)

      三、實驗內(nèi)容與過程

      1、類集應(yīng)用

      范例:實現(xiàn)一個超市管理系統(tǒng),要求可以添加貨物,刪除貨物和查詢貨物:

      。代碼如下:

      public interface Goods { public String getName();// 得到商品名稱

      public int getCount();// 得到商品數(shù)量

      public float getPrice();// 得到商品價格 }

      public class Book implements Goods {

      private String name;private int count;private float price;

      public Book(){ }

      public Book(String name, int count, float price){

      this.name = name;

      this.count = count;

      this.price = price;}

      public String getName(){

      return name;}

      public void setName(String name){

      this.name = name;

      金陵科技學(xué)院實驗報告

      }

      public int getCount(){

      return count;}

      public void setCount(int count){

      this.count = count;}

      public float getPrice(){

      return price;}

      public void setPrice(float price){

      this.price = price;}

      public boolean equals(Object obj){

      if(this == obj){

      return true;

      }

      if(!(obj instanceof Book)){

      return false;

      }

      Book b =(Book)obj;

      if(b.name.equals(this.name)&& b.count == this.count

      && b.price == this.price){

      return true;

      } else {

      return false;

      } }

      public int hashCode(){

      return this.name.hashCode()+ new Integer(this.count).hashCode()

      + new Float(this.price).hashCode();}

      public String toString(){

      return “書名:” + this.name + “;書的價格:” + this.price + “;書的數(shù)量:”

      + this.count;}

      金陵科技學(xué)院實驗報告

      }

      import java.util.ArrayList;import java.util.Iterator;import java.util.List;

      public class SuperMarket { private List allGoods;

      public SuperMarket(){

      this.allGoods = new ArrayList();}

      public void add(Goods goods){

      this.allGoods.add(goods);}

      public void remove(Goods goods){

      this.allGoods.remove(goods);}

      public List search(String keyWord){

      List temp = new ArrayList();

      Iterator iter = this.allGoods.iterator();

      while(iter.hasNext()){

      Goods g = iter.next();

      if(g.getName().indexOf(keyWord)!=-1){

      temp.add(g);

      }

      }

      return temp;}

      public List getAllGoods(){

      return this.allGoods;} }

      import java.util.Iterator;import java.util.List;

      public class Test {

      金陵科技學(xué)院實驗報告

      public static void main(String[] args){

      SuperMarket mak = new SuperMarket();

      mak.add(new Book(“Java”, 2, 30.9f));

      mak.add(new Book(“C++”, 3, 10.9f));

      mak.add(new Book(“JSP”, 5, 80.9f));

      print(mak.search(“J”));

      mak.remove(new Book(“Java”, 2, 30.9f));

      print(mak.search(“J”));}

      public static void print(List all){

      Iterator iter = all.iterator();

      while(iter.hasNext()){

      System.out.println(iter.next());

      } } } 對照范例寫出如下題目:

      (1)寵物商店,要求可以添加、刪除和查找寵物(2)實現(xiàn)以下兩個關(guān)系

      A、一個學(xué)??梢杂卸鄠€學(xué)生,所有學(xué)生屬于一個學(xué)校

      B、一門課程可以有多個學(xué)生選,一個學(xué)生可以選多門課程

      四、實驗結(jié)果與分析(程序運行結(jié)果及其分析)

      五、實驗體會

      金陵科技學(xué)院實驗報告

      實驗項目名稱: Java IO操作

      實驗學(xué)時: 6 同組學(xué)生姓名: 實驗地點: 實驗日期: 實驗成績: 批改教師: 批改時間:

      金陵科技學(xué)院實驗報告

      實驗3 Java IO操作

      一、實驗?zāi)康暮鸵?/p>

      (1)理解輸入輸出流概念(2)掌握文件輸入輸出流

      (3)掌握鍵盤的輸入、顯示器的輸出(4)理解其他輸入輸出流

      二、實驗儀器和設(shè)備

      奔騰以上個人計算機,windows操作系統(tǒng)。

      配置好JDK環(huán)境,安裝集成開發(fā)環(huán)境(Eclipse)

      三、實驗內(nèi)容與過程

      1、編寫類模擬命令Copy

      范例:實現(xiàn)文件的復(fù)制代碼。參考代碼如下:

      File file1 = new File(“d:”+File.seperator +”demo.txt”);

      // 找到第一個文件的File對象

      File file2 = new File(“d:”+File.seperator +”cemo.txt”);// 找到目標(biāo)文件路徑 InputStream input = new FileInputStream(file1);// 輸入流 OutputStream output = new FileOutputStream(file2);// 輸出流 int temp = 0;// 定義一個整數(shù)表示接收的內(nèi)容

      while((temp = input.read())!=-1){ // 表示還有內(nèi)容可以繼續(xù)讀

      output.write(temp);// 寫入數(shù)據(jù) } input.close();// 關(guān)閉 output.close();// 關(guān)閉

      2、通過鍵盤的輸入,實現(xiàn)簡單的選項操作。

      *********XXXX管理系統(tǒng)***********

      [1]添加

      [2]刪除

      [3]修改

      [4]查詢

      [5]退出

      3、編寫一個簡單管理系統(tǒng),實現(xiàn)真實的操作。

      四、實驗結(jié)果與分析(程序運行結(jié)果及其分析)

      五、實驗體會

      金陵科技學(xué)院實驗報告

      實驗項目名稱: JDBC

      實驗學(xué)時: 6 同組學(xué)生姓名: 實驗地點: 實驗日期: 實驗成績: 批改教師: 批改時間:

      金陵科技學(xué)院實驗報告

      實驗4 JDBC

      一、實驗?zāi)康暮鸵螅?)理解JDBC分類

      (2)掌握JDBC數(shù)據(jù)庫連接步驟

      (3)掌握JDBC連接MySQL數(shù)據(jù)庫代碼(4)理解JDBC連接其他數(shù)據(jù)庫方式

      二、實驗儀器和設(shè)備

      奔騰以上個人計算機,windows操作系統(tǒng)。

      配置好JDK環(huán)境,安裝集成開發(fā)環(huán)境(Eclipse)

      三、實驗內(nèi)容與過程

      1、安裝MySQL數(shù)據(jù)庫,配置好數(shù)據(jù)庫

      創(chuàng)建一個數(shù)據(jù)庫表,按要求給出詳細的字段設(shè)計

      pid name age birthday salary

      主要操作:

      2、創(chuàng)建Eclipse項目,配置驅(qū)動包

      每個數(shù)據(jù)庫廠商都會提供對Java開發(fā)技術(shù)的支持,即都會提供對應(yīng)的Java驅(qū)動,也就是一個jar包

      主要操作:

      3、項目中建立一個詳細例子,按照要求連接、操作、關(guān)閉數(shù)據(jù)庫

      按照標(biāo)準(zhǔn)的步驟完成對MySQL數(shù)據(jù)庫的操作

      主要代碼:(添加、修改、刪除和查詢)

      金陵科技學(xué)院實驗報告

      4、試著連接其他類型數(shù)據(jù)庫。

      四、實驗結(jié)果與分析(程序運行結(jié)果及其分析)

      五、實驗體會

      第五篇:Java程序設(shè)計實驗

      學(xué) 生 實 驗 報 告 冊

      課程名稱:

      學(xué)生學(xué)號:

      所屬院部:

      (理工類)

      專業(yè)班級:

      學(xué)生姓名:

      指導(dǎo)教師: ——20 學(xué)年 第 學(xué)期

      金陵科技學(xué)院教務(wù)處制

      實驗報告書寫要求

      實驗報告原則上要求學(xué)生手寫,要求書寫工整。若因課程特點需打印的,標(biāo)題采用四號黑體,正文采用小四號宋體,單倍行距。紙張一律采用A4的紙張。

      實驗報告書寫說明

      實驗報告中實驗?zāi)康暮鸵蟆嶒瀮x器和設(shè)備、實驗內(nèi)容與過程、實驗結(jié)果與分析這四項內(nèi)容為必需項。教師可根據(jù)學(xué)科特點和實驗具體要求增加項目。

      填寫注意事項

      (1)細致觀察,及時、準(zhǔn)確、如實記錄。(2)準(zhǔn)確說明,層次清晰。

      (3)盡量采用專用術(shù)語來說明事物。

      (4)外文、符號、公式要準(zhǔn)確,應(yīng)使用統(tǒng)一規(guī)定的名詞和符號。(5)應(yīng)獨立完成實驗報告的書寫,嚴禁抄襲、復(fù)印,一經(jīng)發(fā)現(xiàn),以零分論處。

      實驗報告批改說明

      實驗報告的批改要及時、認真、仔細,一律用紅色筆批改。實驗報告的批改成績采用五級記分制或百分制,按《金陵科技學(xué)院課堂教學(xué)實施細則》中作業(yè)批閱成績評定要求執(zhí)行。

      實驗報告裝訂要求

      實驗批改完畢后,任課老師將每門課程的每個實驗項目的實驗報告以自然班為單位、按學(xué)號升序排列,裝訂成冊,并附上一份該門課程的實驗大綱。

      金陵科技學(xué)院實驗報告

      實驗項目名稱: 面向?qū)ο缶幊虒嶒?實驗學(xué)時: 8 同組學(xué)生姓名: 實驗地點: 實驗日期: 實驗成績: 批改教師: 批改時間:

      金陵科技學(xué)院實驗報告

      實驗1 面向?qū)ο缶幊虒嶒?/p>

      一、實驗?zāi)康暮鸵?/p>

      (1)理解Java概念、掌握JDK環(huán)境配置(2)熟悉Java開發(fā)過程

      (3)掌握Java面向?qū)ο缶幊袒A(chǔ):封裝、繼承、多態(tài)(4)掌握Java接口編程,理解開發(fā)模式

      二、實驗儀器和設(shè)備

      奔騰以上個人計算機,windows操作系統(tǒng)。

      配置好JDK環(huán)境,安裝集成開發(fā)環(huán)境(Eclipse)

      三、實驗內(nèi)容與過程

      1、JDK環(huán)境配置

      2、面向?qū)ο蟮姆庋b性

      范例:設(shè)計一個表示學(xué)生的類,里面有學(xué)生的三項成績:計算機成績、數(shù)學(xué)成績、英語成績。要求可以求總分、平均分、最高分、最低分,并且可以輸出一個學(xué)生的完整信息。代碼如下: class Student{ private String name;private int age;private float english;private float computer;private float math;public Student(){} public Student(String n,int a,float e,float c,float m){

      this.setName(n);

      this.setAge(a);

      this.setEnglish(e);

      this.setComputer(c);

      this.setMath(m);} public float sum(){

      return english + computer + math;} public float avg(){

      return this.sum()/ 3;} public float max(){

      float max = computer>math?computer:math;

      max = max>english?max:english;

      return max;} public float min(){

      float min = computer

      min = min

      return min;

      金陵科技學(xué)院實驗報告

      } public String getInfo(){

      return “學(xué)生信息: n” +

      “t|-姓名:” + this.getName()+ “n” +

      “t|-年齡:” + this.getAge()+ “n” +

      “t|-數(shù)學(xué)成績:” + this.getMath()+ “n” +

      “t|-英語成績:” + this.getEnglish()+ “n” +

      “t|-計算機成績:” + this.getComputer();} public void setName(String n){

      name = n;} public void setAge(int a){

      age = a;} public void setEnglish(float e){

      english = e;} public void setComputer(float c){

      computer = c;} public void setMath(float m){

      math = m;} public String getName(){

      return name;} public int getAge(){

      return age;} public float getEnglish(){

      return english;} public float getComputer(){

      return computer;} public float getMath(){

      return math;} } public class ExecDemo{ public static void main(String args[]){

      Student stu = new Student(“張三”,30,89.0f,91.0f,87.0f);

      System.out.println(“總分:” + stu.sum());

      金陵科技學(xué)院實驗報告

      }

      } System.out.println(“平均分:” + stu.avg());System.out.println(“最高分:” + stu.max());System.out.println(“最低分:” + stu.min());System.out.println(stu.getInfo());對照范例寫出如下題目:

      (1)編寫并測試一個代表地址的Address類,包括以下的屬性:國家、省份、城市、街道、郵編。注意:

      1、體現(xiàn)封裝

      2、構(gòu)造方法(最少2個)

      3、要有輸出(可以從此地址類中得到一個完整的地址信息)。

      4、測試 主類 main

      (2)定義并測試一個代表員工的Employee類。它的屬性包括“員工姓名”、“員工號碼”、“員工基本薪水”;它的方法包括“構(gòu)造方法”、“獲取員工姓名”、“獲取員工號碼”、“獲取員工基本薪水”、“設(shè)置姓名”、“設(shè)置員工號碼”、“設(shè)置基本薪水”。測試(3)、定義一個圓形類(半徑屬性),封裝、構(gòu)造、整個輸出、可以返回圓的面積與周長。測試

      (4)、思考設(shè)計:一個人有一本書,一本書屬于一個人。

      3、面向?qū)ο蟮睦^承性

      范例:要求定義一個數(shù)組類Array,里面定義了一個整型數(shù)組,但是此整型數(shù)組屬于動態(tài)分配大小,即:所有的大小由程序指定,并在此基礎(chǔ)上實現(xiàn)以下的兩個子類:

      反轉(zhuǎn)類:可以將數(shù)組的內(nèi)容反轉(zhuǎn)排列

      排序類:可以對數(shù)組進行排序的操作 class Array{ private int temp[] = null;// 只是聲明數(shù)組,但是大小未知

      private int foot = 0;// 用于保存下一個的記錄點

      public Array(int len){

      if(len>0){

      this.temp = new int[len];// 此時大小由外部決定

      }else{

      this.temp = new int[1];// 至少開辟一個空間

      } } public boolean add(int i){ // 加入數(shù)據(jù)操作

      if(this.foot

      this.temp[this.foot] = i;// 加入內(nèi)容

      this.foot++;// 改變長度

      return true;// 加入成功返回true

      }else{

      return false;// 加入失敗

      } } public int[] getArray(){ // 返回全部的數(shù)組

      return this.temp;}

      金陵科技學(xué)院實驗報告

      } class SortArray extends Array{ public SortArray(int len){

      super(len);} public int[] getArray(){

      java.util.Arrays.sort(super.getArray());// 排序操作

      return super.getArray();// 返回的是排序后的內(nèi)容

      } } class ReverseArray extends Array{ public ReverseArray(int len){

      super(len);} public int[] getArray(){

      int rt[] = new int[super.getArray().length];// 根據(jù)大小開辟新數(shù)組

      int count = rt.length-1;

      for(int x=0;x

      rt[count] = super.getArray()[x];

      count--;

      }

      return rt;} } public class ArrayDemo{ public static void main(String args[]){

      ReverseArray arr = new ReverseArray(6);

      System.out.println(arr.add(3));

      System.out.println(arr.add(23));

      System.out.println(arr.add(1));

      System.out.println(arr.add(5));

      System.out.println(arr.add(6));

      System.out.println(arr.add(8));

      System.out.println(arr.add(11));

      System.out.println(arr.add(16));

      print(arr.getArray());} public static void print(int i[]){

      for(int x=0;x

      System.out.print(i[x] + “、”);

      } } }

      金陵科技學(xué)院實驗報告

      對照范例寫出如下題目:

      (1).創(chuàng)建GrandFather類,其中包括

      a)屬性:姓名(name),年齡(age)

      b)方法getGrandFather():顯示爺爺?shù)男畔?/p>

      c)構(gòu)造方法:給爺爺?shù)男彰?,年齡賦值(2).創(chuàng)建Father類,繼承Grandfather類 a)屬性:除了繼承爺爺?shù)膶傩砸酝?,還要增加自己的屬性:“職業(yè)”(occupation)b)構(gòu)造方法:顯式調(diào)用父類的構(gòu)造方法,為Father類的姓名和年齡賦初始值。再為職業(yè)輸入初始值。

      c)方法getFather(): 顯示父親的相關(guān)信息

      (3).創(chuàng)建ClassMain()類,定義main()方法,構(gòu)造GrandFather類的對象和Father類的對象,并分別顯示詳細信息。

      3、面向?qū)ο蠖鄳B(tài)性

      范例:計算柱體的體積。柱體體積計算公式是:底部面積乘以高度 柱體底部分為 圓形和矩形 要求:通過抽象類和多態(tài)實現(xiàn) package cn.jit.demo;abstract class Bottom { //父類抽象類 底部

      public abstract double calculatorArea();} class CircleBottom extends Bottom{ //圓形底

      /** * 半徑

      */ private double radius;

      @Override public double calculatorArea(){

      return Math.PI * radius * radius;} public double getRadius(){

      return radius;} public void setRadius(double radius){

      this.radius = radius;} public CircleBottom(double radius){

      super();

      this.radius = radius;} } class SquareBottom extends Bottom{ //矩形底

      private double sideA;

      金陵科技學(xué)院實驗報告

      private double sideB;public double getSideA(){

      return sideA;} public void setSideA(double sideA){

      this.sideA = sideA;} public double getSideB(){

      return sideB;} public void setSideB(double sideB){

      this.sideB = sideB;} @Override public double calculatorArea(){

      return sideA * sideB;} public SquareBottom(double sideA, double sideB){

      super();

      this.sideA = sideA;

      this.sideB = sideB;} } class ZhuTi { //柱體類,完成形狀的拼裝

      /** * 底

      */ private Bottom bottom;/** * 高

      */ private double height;/** * 計算體積

      * @return */ public double calculatorVolumn(){

      return bottom.calculatorArea()* height;} public ZhuTi(Bottom bottom, double height){

      super();

      this.bottom = bottom;

      this.height = height;

      金陵科技學(xué)院實驗報告

      } public Bottom getBottom(){

      return bottom;} public void setBottom(Bottom bottom){

      this.bottom = bottom;} public double getHeight(){

      return height;} public void setHeight(double height){

      this.height = height;} public void changeBottom(Bottom bottom){

      this.bottom = bottom;} } public class VolumnTest { //測試類

      public static void main(String[] args){

      Bottom bottom = new CircleBottom(1.0);

      double height = 1.0;

      ZhuTi zhuTi = new ZhuTi(bottom,height);

      double result = zhuTi.calculatorVolumn();

      System.out.println(“圓柱體的體積是:” + result);

      bottom = new SquareBottom(1.0,1.0);

      zhuTi.changeBottom(bottom);

      result = zhuTi.calculatorVolumn();

      System.out.println(“立方體的體積是:” + result);} } 范例:接口和多態(tài)的應(yīng)用,例如:電腦上實現(xiàn)了USB接口,U盤,打印機等等也都實現(xiàn)了此標(biāo)準(zhǔn)。interface USB{ public void start();// 開始工作

      public void stop();// 結(jié)束工作 } class Computer{ public static void plugin(USB usb){

      usb.start();

      usb.stop();} };class Flash implements USB{ public void start(){

      金陵科技學(xué)院實驗報告

      System.out.println(“U盤開始工作?!?;} public void stop(){

      System.out.println(“U盤停止工作?!?;} };class Print implements USB{ public void start(){

      System.out.println(“打印機開始工作。”);} public void stop(){

      System.out.println(“打印機停止工作。”);} };public class InterPolDemo02{ public static void main(String args[]){

      Computer.plugin(new Flash());

      Computer.plugin(new Print());} };對照范例,寫出以下程序:(1)樂器(Instrument)的標(biāo)準(zhǔn)為彈奏(play),而樂器類型分為:鋼琴(Piano)和小提琴(Violin),各種樂器的彈奏方法各不同。編寫代碼實現(xiàn)不同樂器的彈奏。(2)計算機模擬

      四、實驗結(jié)果與分析(程序運行結(jié)果及其分析)

      五、實驗體會

      金陵科技學(xué)院實驗報告

      實驗項目名稱: 類集

      實驗學(xué)時: 4 同組學(xué)生姓名: 實驗地點: 實驗日期: 實驗成績: 批改教師: 批改時間:

      金陵科技學(xué)院實驗報告

      實驗2 類集

      一、實驗?zāi)康暮鸵螅?)理解類集概念

      (2)熟悉Collection接口、List接口、Set接口和Map接口(3)掌握ArrayList類、HashSet類和TreeSet類(4)理解TreeMap、HashMap

      二、實驗儀器和設(shè)備

      奔騰以上個人計算機,windows操作系統(tǒng)。

      配置好JDK環(huán)境,安裝集成開發(fā)環(huán)境(Eclipse)

      三、實驗內(nèi)容與過程

      1、類集應(yīng)用

      范例:實現(xiàn)一個超市管理系統(tǒng),要求可以添加貨物,刪除貨物和查詢貨物:

      。代碼如下:

      public interface Goods { public String getName();// 得到商品名稱

      public int getCount();// 得到商品數(shù)量

      public float getPrice();// 得到商品價格 }

      public class Book implements Goods {

      private String name;private int count;private float price;

      public Book(){ }

      public Book(String name, int count, float price){

      this.name = name;

      this.count = count;

      this.price = price;}

      public String getName(){

      return name;}

      public void setName(String name){

      this.name = name;

      金陵科技學(xué)院實驗報告

      }

      public int getCount(){

      return count;}

      public void setCount(int count){

      this.count = count;}

      public float getPrice(){

      return price;}

      public void setPrice(float price){

      this.price = price;}

      public boolean equals(Object obj){

      if(this == obj){

      return true;

      }

      if(!(obj instanceof Book)){

      return false;

      }

      Book b =(Book)obj;

      if(b.name.equals(this.name)&& b.count == this.count

      && b.price == this.price){

      return true;

      } else {

      return false;

      } }

      public int hashCode(){

      return this.name.hashCode()+ new Integer(this.count).hashCode()

      + new Float(this.price).hashCode();}

      public String toString(){

      return “書名:” + this.name + “;書的價格:” + this.price + “;書的數(shù)量:”

      + this.count;}

      金陵科技學(xué)院實驗報告

      }

      import java.util.ArrayList;import java.util.Iterator;import java.util.List;

      public class SuperMarket { private List allGoods;

      public SuperMarket(){

      this.allGoods = new ArrayList();}

      public void add(Goods goods){

      this.allGoods.add(goods);}

      public void remove(Goods goods){

      this.allGoods.remove(goods);}

      public List search(String keyWord){

      List temp = new ArrayList();

      Iterator iter = this.allGoods.iterator();

      while(iter.hasNext()){

      Goods g = iter.next();

      if(g.getName().indexOf(keyWord)!=-1){

      temp.add(g);

      }

      }

      return temp;}

      public List getAllGoods(){

      return this.allGoods;} }

      import java.util.Iterator;import java.util.List;

      public class Test {

      金陵科技學(xué)院實驗報告

      public static void main(String[] args){

      SuperMarket mak = new SuperMarket();

      mak.add(new Book(“Java”, 2, 30.9f));

      mak.add(new Book(“C++”, 3, 10.9f));

      mak.add(new Book(“JSP”, 5, 80.9f));

      print(mak.search(“J”));

      mak.remove(new Book(“Java”, 2, 30.9f));

      print(mak.search(“J”));}

      public static void print(List all){

      Iterator iter = all.iterator();

      while(iter.hasNext()){

      System.out.println(iter.next());

      } } } 對照范例寫出如下題目:

      (1)寵物商店,要求可以添加、刪除和查找寵物(2)實現(xiàn)以下兩個關(guān)系

      A、一個學(xué)??梢杂卸鄠€學(xué)生,所有學(xué)生屬于一個學(xué)校

      B、一門課程可以有多個學(xué)生選,一個學(xué)生可以選多門課程

      四、實驗結(jié)果與分析(程序運行結(jié)果及其分析)

      五、實驗體會

      金陵科技學(xué)院實驗報告

      實驗項目名稱: Java IO操作

      實驗學(xué)時: 6 同組學(xué)生姓名: 實驗地點: 實驗日期: 實驗成績: 批改教師: 批改時間:

      金陵科技學(xué)院實驗報告

      實驗3 Java IO操作

      一、實驗?zāi)康暮鸵?/p>

      (1)理解輸入輸出流概念(2)掌握文件輸入輸出流

      (3)掌握鍵盤的輸入、顯示器的輸出(4)理解其他輸入輸出流

      二、實驗儀器和設(shè)備

      奔騰以上個人計算機,windows操作系統(tǒng)。

      配置好JDK環(huán)境,安裝集成開發(fā)環(huán)境(Eclipse)

      三、實驗內(nèi)容與過程

      1、編寫類模擬命令Copy

      范例:實現(xiàn)文件的復(fù)制代碼。參考代碼如下:

      File file1 = new File(“d:”+File.seperator +”demo.txt”);

      // 找到第一個文件的File對象

      File file2 = new File(“d:”+File.seperator +”cemo.txt”);// 找到目標(biāo)文件路徑 InputStream input = new FileInputStream(file1);// 輸入流 OutputStream output = new FileOutputStream(file2);// 輸出流 int temp = 0;// 定義一個整數(shù)表示接收的內(nèi)容

      while((temp = input.read())!=-1){ // 表示還有內(nèi)容可以繼續(xù)讀

      output.write(temp);// 寫入數(shù)據(jù) } input.close();// 關(guān)閉 output.close();// 關(guān)閉

      2、通過鍵盤的輸入,實現(xiàn)簡單的選項操作。

      *********XXXX管理系統(tǒng)***********

      [1]添加

      [2]刪除

      [3]修改

      [4]查詢

      [5]退出

      3、編寫一個簡單管理系統(tǒng),實現(xiàn)真實的操作。

      四、實驗結(jié)果與分析(程序運行結(jié)果及其分析)

      五、實驗體會

      金陵科技學(xué)院實驗報告

      實驗項目名稱: JDBC

      實驗學(xué)時: 6 同組學(xué)生姓名: 實驗地點: 實驗日期: 實驗成績: 批改教師: 批改時間:

      金陵科技學(xué)院實驗報告

      實驗4 JDBC

      一、實驗?zāi)康暮鸵螅?)理解JDBC分類

      (2)掌握JDBC數(shù)據(jù)庫連接步驟

      (3)掌握JDBC連接MySQL數(shù)據(jù)庫代碼(4)理解JDBC連接其他數(shù)據(jù)庫方式

      二、實驗儀器和設(shè)備

      奔騰以上個人計算機,windows操作系統(tǒng)。

      配置好JDK環(huán)境,安裝集成開發(fā)環(huán)境(Eclipse)

      三、實驗內(nèi)容與過程

      1、安裝MySQL數(shù)據(jù)庫,配置好數(shù)據(jù)庫

      創(chuàng)建一個數(shù)據(jù)庫表,按要求給出詳細的字段設(shè)計

      pid name age birthday salary

      主要操作:

      2、創(chuàng)建Eclipse項目,配置驅(qū)動包

      每個數(shù)據(jù)庫廠商都會提供對Java開發(fā)技術(shù)的支持,即都會提供對應(yīng)的Java驅(qū)動,也就是一個jar包

      主要操作:

      3、項目中建立一個詳細例子,按照要求連接、操作、關(guān)閉數(shù)據(jù)庫

      按照標(biāo)準(zhǔn)的步驟完成對MySQL數(shù)據(jù)庫的操作

      主要代碼:(添加、修改、刪除和查詢)

      金陵科技學(xué)院實驗報告

      4、試著連接其他類型數(shù)據(jù)庫。

      四、實驗結(jié)果與分析(程序運行結(jié)果及其分析)

      五、實驗體會

      下載java實驗4(共5篇)word格式文檔
      下載java實驗4(共5篇).doc
      將本文檔下載到自己電腦,方便修改和收藏,請勿使用迅雷等下載。
      點此處下載文檔

      文檔為doc格式


      聲明:本文內(nèi)容由互聯(lián)網(wǎng)用戶自發(fā)貢獻自行上傳,本網(wǎng)站不擁有所有權(quán),未作人工編輯處理,也不承擔(dān)相關(guān)法律責(zé)任。如果您發(fā)現(xiàn)有涉嫌版權(quán)的內(nèi)容,歡迎發(fā)送郵件至:645879355@qq.com 進行舉報,并提供相關(guān)證據(jù),工作人員會在5個工作日內(nèi)聯(lián)系你,一經(jīng)查實,本站將立刻刪除涉嫌侵權(quán)內(nèi)容。

      相關(guān)范文推薦

        Java Web實驗教案

        Java Web實驗教案 宋國柱 2012-2-20 實驗一 tomcat服務(wù)器下載與配置及Myeclipse簡介 1. 實驗?zāi)繕?biāo) ? 掌握tomcat服務(wù)器的配置及使用 ? 掌握Myeclipse開發(fā)工具 2. 知識講解 一......

        java實驗報告實驗2答案(共5篇)

        互聯(lián)網(wǎng)軟件應(yīng)用與開發(fā)實驗指導(dǎo)書 實驗二 熟悉Applet,GUI編程 實驗?zāi)康模?本實驗旨在鞏固同學(xué)們對上課所講Applet,異常處理,java的控制加深理解,圖形用戶界面基本組件窗口、按鈕、......

        java實驗 報告(寫寫幫整理)

        專業(yè)選修課程實驗(1)實驗報告 課程名稱____ JAVA程序設(shè)計 學(xué)生學(xué)院__ 計算機學(xué)院______ 專業(yè)班級___ 12計科6班 學(xué) 號____ 3112006006 學(xué)生姓名____ 黃新健 指導(dǎo)教師______......

        河南工業(yè)大學(xué)java實驗四

        Henan University of Technology Experiment’s Report 班級計科1201 姓名: 學(xué)號201216010506 成績實驗4—— Java的輸入機制 I 實驗?zāi)康?(1) . Java如何操作文件 (2) .了解J......

        Java及Javaweb(jsp)實驗1

        實驗1:Java類與對象 一、實驗?zāi)康?(1)掌握Java類的繼承關(guān)系和派生方法。 (2)理解多態(tài)的概念與使用。 (3)掌握接口的定義和使用。 二、實驗任務(wù) (1)按要求編寫一個Java程序。 (2)按要求......

        Java實驗8實習(xí)報告.

        實驗題 1 學(xué)生信息管理函數(shù)。 數(shù)據(jù)庫中的信息參考 Exp9.1.txt , 這些命令用來創(chuàng)建 student 表, 包含學(xué)生的學(xué)號、 姓名、 年齡信息。 ① 根據(jù)學(xué)號,可以查詢到學(xué)生的姓名和年......

        java流實驗內(nèi)容及代碼

        實驗7 流(2學(xué)時) 一、實驗?zāi)康?1. 熟悉流類庫中各種常用流的使用方法。 2. 能夠使用流類實現(xiàn)基本的文件讀寫。 二、實驗內(nèi)容 1. 編寫程序,在控制臺窗口提示輸入兩個整數(shù),然后接......