




已閱讀5頁,還剩3頁未讀, 繼續(xù)免費閱讀
版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
實驗報告2013學年第 1 學期 任課老師: 課程名稱Java語言與系統(tǒng)設計班級學號姓名實驗名稱實驗三 輸入和輸出實驗時間實驗環(huán)境PC/windows2000/2003/XP/Jcreator Pro/JBuild/JDK Eclipse/。實驗目的和內(nèi)容要求實驗3輸入和輸出1實驗目的了解流式輸入輸出的基本原理;掌握類File、FileInputStream、FileOutputStream的使用方法。2實驗內(nèi)容(1)編程:檢查C:WINDOWSsetuplog.txt文件是否存在,若在則顯示該文件的名稱和內(nèi)容。(2)編程:輸入5個學生的信息(包含學號、姓名、3科成績),統(tǒng)計各學生的總分,然后將學生信息和統(tǒng)計結果存入二進制數(shù)據(jù)文件STUDENT.DAT中。(3)編程:從第(2)題中建立的STUDENT.DAT文件中讀取數(shù)據(jù),尋找平均分最高的學生,并輸出該學生的所有信息。3實驗要求編程時,應考慮異常處理。實驗過程記錄(學生寫出實驗步驟及中間的結果與現(xiàn)象,在實驗中做了什么,怎么做,發(fā)生的現(xiàn)象和中間結果)1. 先分析題意,想好大概思路,然后按照功能劃分建立幾個類。2. 第一個建立的類,命名為Check用于判斷該目錄下文件夾是否存在,存在則輸出該文件的內(nèi)容,否則返回false。3. 第二個建立的Student類,成員變量主要有姓名、學號、語文成績、數(shù)學成績、英語成績,以及總分,構造與此相關的set和get方法,與重載的構造方法來賦值。4. 第三個建立的是StudentInfo類,用于輸入學生信息,并將其存儲于STUDENT.DAT文件中,然后讀取其中內(nèi)容,判斷后把總分最高的學生信息輸出。5.實驗思路分析完成后實驗進行并不順利,經(jīng)常丟三落四,找同學幫忙抓bug才勉強完成,但最后在自己電腦上完成時卻一直沒有像別人一樣輸出文件名稱和內(nèi)容,最后才發(fā)現(xiàn)是自己的電腦中沒有那個文件。實驗結果分析與總結程序運行結果(請?zhí)峁┧瓿傻母鞯李}運行結果界面截圖):(1)(制作了一個相應文件后檢測到的截圖)(2)指導老師評閱意見指導老師: 年 月 日填寫內(nèi)容時,可把表格擴大。附:實驗源程序代碼/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+文件標志位為:+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(請輸入第+(i+1)+個學生的學號); numberi=s.nextInt(); System.out.println(請輸入第+(i+1)+個學生的姓名); namei=s.next(); System.out.println(請輸入第+(i+1)+個學生的語文成績); ChinScorei=s.nextInt(); System.out.println(請輸入第+(i+1)+個學生的數(shù)學成績); MathScorei=s.nextInt(); System.out.println(請輸入第+(i+1)+個學生的英語成績); 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+個學生的總成績?yōu)?studentj.getNum(); catch (Exception e) e.printStackTrace(); for(int m=0;m5;m+) while(mstude
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 南門小學租房合同范本
- 架子班組勞務分包合同范本
- 合作建設開發(fā)合同范本
- 口罩機居間合同范本
- 農(nóng)村自建車庫合同范本
- 豐臺區(qū)供暖安裝合同范本
- 卡車賣買合同范本
- 上班工位安裝合同范本
- 手機分期電子合同范本
- 再生碎石加工承包合同范本
- (完整word版)服務質(zhì)量評價表
- 2022年高考(全國甲卷)語文仿真模擬卷【含答案】
- 腸瘺治療PPT醫(yī)學課件(PPT 25頁)
- 員工轉(zhuǎn)正評價表
- 道路交通事故責任認定行政復議申請書范例
- 鄭州大學圖書館平立剖面效果圖
- 高效液相含量測定計算公式
- 公安機關通用告知書模板
- 《小學數(shù)學課程與教學》教學大綱
- 《手機攝影》全套課件(完整版)
- 礦井無計劃停電停風安全技術措施
評論
0/150
提交評論