




已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实验报告2013学年第 1 学期 任课老师: 课程名称Java语言与系统设计班级学号姓名实验名称实验三 输入和输出实验时间实验环境PC/windows2000/2003/XP/Jcreator Pro/JBuild/JDK Eclipse/。实验目的和内容要求实验3输入和输出1实验目的了解流式输入输出的基本原理;掌握类File、FileInputStream、FileOutputStream的使用方法。2实验内容(1)编程:检查C:WINDOWSsetuplog.txt文件是否存在,若在则显示该文件的名称和内容。(2)编程:输入5个学生的信息(包含学号、姓名、3科成绩),统计各学生的总分,然后将学生信息和统计结果存入二进制数据文件STUDENT.DAT中。(3)编程:从第(2)题中建立的STUDENT.DAT文件中读取数据,寻找平均分最高的学生,并输出该学生的所有信息。3实验要求编程时,应考虑异常处理。实验过程记录(学生写出实验步骤及中间的结果与现象,在实验中做了什么,怎么做,发生的现象和中间结果)1. 先分析题意,想好大概思路,然后按照功能划分建立几个类。2. 第一个建立的类,命名为Check用于判断该目录下文件夹是否存在,存在则输出该文件的内容,否则返回false。3. 第二个建立的Student类,成员变量主要有姓名、学号、语文成绩、数学成绩、英语成绩,以及总分,构造与此相关的set和get方法,与重载的构造方法来赋值。4. 第三个建立的是StudentInfo类,用于输入学生信息,并将其存储于STUDENT.DAT文件中,然后读取其中内容,判断后把总分最高的学生信息输出。5.实验思路分析完成后实验进行并不顺利,经常丢三落四,找同学帮忙抓bug才勉强完成,但最后在自己电脑上完成时却一直没有像别人一样输出文件名称和内容,最后才发现是自己的电脑中没有那个文件。实验结果分析与总结程序运行结果(请提供所完成的各道题运行结果界面截图):(1)(制作了一个相应文件后检测到的截图)(2)指导老师评阅意见指导老师: 年 月 日填写内容时,可把表格扩大。附:实验源程序代码/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)+个学生的数学成绩); 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+个学生的总成绩为+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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 不同序列聘任管理办法
- 业务订单处理管理办法
- 规划艺术作坊管理办法
- 调度中心消防管理办法
- 上海项目团队管理办法
- 贡井区项目管理办法
- 专项工程招标管理办法
- 菜园子种植管理办法
- 规模猪场饲料管理办法
- 专业分包物资管理办法
- 水轮发电机讲义课件
- 姜黄素合成路线
- 高中通用技术会考试题及详解
- 安全教育:不私自离开幼儿园
- 泛光施工招标文件
- 刑法各论(第四版全书电子教案完整版ppt整套教学课件最全教学教程)
- 人工挖孔桩施工监测监控措施
- 第7章:方差分析课件
- 国家职业技能标准 (2021年版) 6-18-01-07 多工序数控机床操作调整工
- 办公楼加层改造施工组织设计(100页)
- DS6-K5B计算机联锁系统介绍文稿
评论
0/150
提交评论