录入学生成绩并写出到磁盘文件
来源:互联网 发布:大型投资理财网站源码 编辑:程序博客网 时间:2024/06/08 18:30
package com.ibeifeng;import java.io.BufferedWriter;import java.io.FileWriter;import java.io.IOException;import java.util.Scanner;/* * 4题目:有五个学生,每个学生有3门课的成绩, * 从键盘输入以上数据(包括学生号,姓名,三门课成绩), * 计算出平均成绩, * 把原有的数据和计算出的平均分数存放在磁盘文件 "student.txt "中。(15分)*/public class Demo4 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); BufferedWriter bw=null; try { bw = new BufferedWriter(new FileWriter("student.txt")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { bw.write("学号-姓名-语文-数学-英语-平均分"); bw.newLine(); bw.flush(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } boolean flag = true; while(flag) { System.out.println("请输入学生姓名"); String name = sc.next(); System.out.println("请输入学生学号"); String num = sc.next(); System.out.println("请输入学生chinese"); double chinese = sc.nextDouble(); System.out.println("请输入学生math"); double math = sc.nextDouble(); System.out.println("请输入学生english"); double english = sc.nextDouble(); Student stu = new Student(name,num,chinese,math,english); System.out.println("别输入了,(y/n)"); if("n".equalsIgnoreCase(sc.next())) { flag=false; } //写入文件 try { bw.write(stu.toString()); bw.newLine(); bw.flush(); } catch (IOException e) { e.printStackTrace(); } } //关闭 if(bw!=null) { try { bw.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } System.out.println("over"); }}class Student { private String name; private String num; private double chinese; private double math; private double english; private double avg; public Student(String name, String num, double chinese, double math, double english) { super(); this.name = name; this.num = num; this.chinese = chinese; this.math = math; this.english = english; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getNum() { return num; } public void setNum(String num) { this.num = num; } public double getChinese() { return chinese; } public void setChinese(double chinese) { this.chinese = chinese; } public double getMath() { return math; } public void setMath(double math) { this.math = math; } public double getEnglish() { return english; } public void setEnglish(double english) { this.english = english; } public double getAvg() { return (chinese+math+english)/3; } @Override public String toString() { return num+"-"+name+"-"+chinese+"-"+math+"-"+english+"-"+getAvg(); }}
0 0
- 录入学生成绩并写出到磁盘文件
- 统计学生成绩,并存储到磁盘文件中
- 统计学生成绩并排序,最后存储到磁盘文件中
- IO综合练习:录入学生成绩并将信息存储在硬盘文件中
- 学生成绩录入
- 学生成绩录入
- 学生成绩录入
- 学生成绩录入
- 学生的成绩录入
- 学生成绩录入
- 学生成绩录入
- 学生成绩录入
- 文件操作---录入成绩并计算均分,写到文件中,打印到屏幕上
- 键盘录入多名学生的信息: 格式:姓名,数学成绩,语文成绩,英文成绩,按总分由高到低 将学生的信息进行排列到文件中
- 2.请把学生名与考试分数录入到Map中,并按分数显示前三名成绩学员的名字。
- 请把学生名与考试分数录入到Map中,并按分数显示前三名成绩学员的名字
- 学生成绩的录入排列
- 键盘录入5个学生信息(姓名,语文成绩,数学成绩,英语成绩),按照总分从高到低输出到控制台
- 动脑筋 + 动脑筋 + 动脑筋 + …… + 动脑筋 = 科学画报
- android开发中常用的快捷键
- HTTP请求与响应码
- Hbuider hybrid app开发之地图位置信息操作方法
- block
- 录入学生成绩并写出到磁盘文件
- sqlserver查看死锁
- POJ 2251Dungeon Master
- JAVA发送HTTP请求,并接受返回内容
- css3 box-sizing属性
- Hdu 5744 Keep On Movin【思维】
- iOS开发-自定义控件的方式及注意
- ffmpeg使用参数的中文说明
- SpringMVC给控制器添加自定义注解控制访问权限(未测试)