java輸入和輸出實(shí)驗(yàn)報(bào)告.doc_第1頁(yè)
java輸入和輸出實(shí)驗(yàn)報(bào)告.doc_第2頁(yè)
java輸入和輸出實(shí)驗(yàn)報(bào)告.doc_第3頁(yè)
java輸入和輸出實(shí)驗(yàn)報(bào)告.doc_第4頁(yè)
java輸入和輸出實(shí)驗(yàn)報(bào)告.doc_第5頁(yè)
已閱讀5頁(yè),還剩3頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

實(shí)驗(yàn)報(bào)告2013學(xué)年第 1 學(xué)期 任課老師: 課程名稱Java語(yǔ)言與系統(tǒng)設(shè)計(jì)班級(jí)學(xué)號(hào)姓名實(shí)驗(yàn)名稱實(shí)驗(yàn)三 輸入和輸出實(shí)驗(yàn)時(shí)間實(shí)驗(yàn)環(huán)境PC/windows2000/2003/XP/Jcreator Pro/JBuild/JDK Eclipse/。實(shí)驗(yàn)?zāi)康暮蛢?nèi)容要求實(shí)驗(yàn)3輸入和輸出1實(shí)驗(yàn)?zāi)康牧私饬魇捷斎胼敵龅幕驹?;掌握類File、FileInputStream、FileOutputStream的使用方法。2實(shí)驗(yàn)內(nèi)容(1)編程:檢查C:WINDOWSsetuplog.txt文件是否存在,若在則顯示該文件的名稱和內(nèi)容。(2)編程:輸入5個(gè)學(xué)生的信息(包含學(xué)號(hào)、姓名、3科成績(jī)),統(tǒng)計(jì)各學(xué)生的總分,然后將學(xué)生信息和統(tǒng)計(jì)結(jié)果存入二進(jìn)制數(shù)據(jù)文件STUDENT.DAT中。(3)編程:從第(2)題中建立的STUDENT.DAT文件中讀取數(shù)據(jù),尋找平均分最高的學(xué)生,并輸出該學(xué)生的所有信息。3實(shí)驗(yàn)要求編程時(shí),應(yīng)考慮異常處理。實(shí)驗(yàn)過(guò)程記錄(學(xué)生寫出實(shí)驗(yàn)步驟及中間的結(jié)果與現(xiàn)象,在實(shí)驗(yàn)中做了什么,怎么做,發(fā)生的現(xiàn)象和中間結(jié)果)1. 先分析題意,想好大概思路,然后按照功能劃分建立幾個(gè)類。2. 第一個(gè)建立的類,命名為Check用于判斷該目錄下文件夾是否存在,存在則輸出該文件的內(nèi)容,否則返回false。3. 第二個(gè)建立的Student類,成員變量主要有姓名、學(xué)號(hào)、語(yǔ)文成績(jī)、數(shù)學(xué)成績(jī)、英語(yǔ)成績(jī),以及總分,構(gòu)造與此相關(guān)的set和get方法,與重載的構(gòu)造方法來(lái)賦值。4. 第三個(gè)建立的是StudentInfo類,用于輸入學(xué)生信息,并將其存儲(chǔ)于STUDENT.DAT文件中,然后讀取其中內(nèi)容,判斷后把總分最高的學(xué)生信息輸出。5.實(shí)驗(yàn)思路分析完成后實(shí)驗(yàn)進(jìn)行并不順利,經(jīng)常丟三落四,找同學(xué)幫忙抓bug才勉強(qiáng)完成,但最后在自己電腦上完成時(shí)卻一直沒(méi)有像別人一樣輸出文件名稱和內(nèi)容,最后才發(fā)現(xiàn)是自己的電腦中沒(méi)有那個(gè)文件。實(shí)驗(yàn)結(jié)果分析與總結(jié)程序運(yùn)行結(jié)果(請(qǐng)?zhí)峁┧瓿傻母鞯李}運(yùn)行結(jié)果界面截圖):(1)(制作了一個(gè)相應(yīng)文件后檢測(cè)到的截圖)(2)指導(dǎo)老師評(píng)閱意見(jiàn)指導(dǎo)老師: 年 月 日填寫內(nèi)容時(shí),可把表格擴(kuò)大。附:實(shí)驗(yàn)源程序代碼/Check類package Exercise;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;/* * author miao_shadow * since 2013-11-25* */public class Check public static void main(String args) Check check=new Check(); try boolean sign=check.CheckCheck();System.out.println(rn+文件標(biāo)志位為:+sign);if(sign=false)System.out.println(該文件不存在!); catch (IOException e) e.printStackTrace();public boolean CheckExist() throws IOExceptionFile file=new File(C:/WINDOWS/setuplog.txt);if(file.exists()System.out.println(該文件存在。+file.getAbsolutePath();try FileInputStream fis=new FileInputStream(file);int i=fis.read();while(i!=-1)System.out.print(char)i);i=fis.read();fis.close();return true; catch (FileNotFoundException e) e.printStackTrace();return false;/Student類package Exercise;import java.io.Serializable;/* * Student類 * author miao_shadow * since 2013-11-25 * */public class Student implements Serializable private int number; private String name; private int ChinScore; private int MathScore; private int EngScore; private int num; public Student(int number,String name,int ChinScore,int MathScore,int EngScore,int num) this.setNumber(number); this.setName(name); this.setChinScore(ChinScore); this.setMathScore(MathScore); this.setEngScore(EngScore); this.setNum(num); public Student() public void setNumber(int number2) this.number = number2; public int getNumber() return number; public void setName(String name) = name; public String getName() return name; public void setChinScore(int chinScore) ChinScore = chinScore; public int getChinScore() return ChinScore; public void setMathScore(int mathScore) MathScore = mathScore; public int getMathScore() return MathScore; public void setEngScore(int engScore) EngScore = engScore; public int getEngScore() return EngScore; public void setNum(int num) this.num = num; public int getNum() return num; /StudentInfo類package Exercise;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;import java.util.Scanner;/* * author miao_shadow * since 2013-11-25 * */public class StudentInfo public static void main(String args) throws IOException StudentInfo si=new StudentInfo();int number=new int5;Student stu=new Student5;String name=new String5;int ChinScore=new int5;int MathScore=new int5;int EngScore=new int5;FileInputStream fis = null;FileOutputStream fos=null;ObjectInputStream ois;File file=new File(C:/Users/Administrator/Desktop/STUDENT.DAT);if(!file.exists()tryfile=new File(C:/Users/Administrator/Desktop/STUDENT.DAT);catch(Exception e)e.printStackTrace();fis=new FileInputStream(file);ois=new ObjectInputStream(fis);fos=new FileOutputStream(file);ObjectOutputStream o=new ObjectOutputStream(fos);Student student=new Student5;try for(int i=0;i5;i+) Scanner s=new Scanner(System.in); System.out.println(請(qǐng)輸入第+(i+1)+個(gè)學(xué)生的學(xué)號(hào)); numberi=s.nextInt(); System.out.println(請(qǐng)輸入第+(i+1)+個(gè)學(xué)生的姓名); namei=s.next(); System.out.println(請(qǐng)輸入第+(i+1)+個(gè)學(xué)生的語(yǔ)文成績(jī)); ChinScorei=s.nextInt(); System.out.println(請(qǐng)輸入第+(i+1)+個(gè)學(xué)生的數(shù)學(xué)成績(jī)); MathScorei=s.nextInt(); System.out.println(請(qǐng)輸入第+(i+1)+個(gè)學(xué)生的英語(yǔ)成績(jī)); EngScorei=s.nextInt(); int num=ChinScorei+MathScorei+EngScorei; stui=new Student(numberi,namei,ChinScorei,MathScorei,EngScorei,num); o.writeObject(stui); catch (FileNotFoundException e) e.printStackTrace(); Student st=new Student();for(int j=0;j5;j+) try studentj=(Student)ois.readObject();System.out.println(第+i+個(gè)學(xué)生的總成績(jī)?yōu)?studentj.getNum(); catch (Exception e) e.printStackTrace(); for(int m=0;m5;m+) while(mstude

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論