62,614
社区成员
发帖
与我相关
我的任务
分享
/*
*题目:有五个学生,每个学生有3门课的成绩,从键盘输入以上数据(包括学生号,姓名,
三门课成绩),计算出平均成绩,况原有的数据和计算出的平均分数存放在磁盘文件
"stud "中。
**/
package com.cn.testquestion;
import java.io.*;
public class StudentGrate
{
public static void main(String args[])throws Exception
{
Student[] student={
new Student("10001","LiNing",88,99,68),
new Student("10002","LiLie",80,79,85),
new Student("10003","YunFei",88,90,67),
new Student("10004","ChunLi",55,91,73),
new Student("10005","ZhangSan",96,80,75)
};
/*
Student student1=new Student("10001","LiNing",88,99,68);
Student student2=new Student("10002","LiLie",80,79,85);
Student student3=new Student("10003","YunFei",88,90,67);
Student student4=new Student("10004","ChunLi",55,91,73);
Student student5=new Student("10005","ZhangSan",96,80,75);
*/
for(int i=0;i<student.length;i++)
{
new FileStudent(student[i]).toFileIn();
}
}
}
class Student
{
private String xuehao;
private String name;
private int shuxue;
private int yuwen;
private int yingyu;
private int average;
public Student(String xuehao,String name,int shuxue,int yuwen,int yingyu)
{
this.xuehao=xuehao;
this.name=name;
this.shuxue=shuxue;
this.yuwen=yuwen;
this.yingyu=yingyu;
this.average=(this.shuxue+this.yuwen+this.yingyu)/3;
}
public String toString()
{
return "学号:"+this.xuehao+" 姓名:"+this.name+" 数学成绩:"+this.shuxue+" 语文成绩:"+this.yuwen+" 英语成绩:"+this.yingyu+" 平均成绩:"+this.average+" === ";
}
}
class FileStudent
{
private static String str="";
private Student person;
public FileStudent(Object person)
{
this.person=(Student)person;
}
public void toFileIn()throws Exception
{
//String str="";
File file=new File("stud.txt");
if(!file.exists())
file.createNewFile();
//else
// System.out.println("文件已经存在。。。");
FileWriter fileto=new FileWriter(file);
str=str+person.toString();
fileto.write(str);
fileto.close();
}
}
/*
*题目:有五个学生,每个学生有3门课的成绩,从键盘输入以上数据(包括学生号,姓名,
三门课成绩),计算出平均成绩,况原有的数据和计算出的平均分数存放在磁盘文件
"stud "中。
**/
package com.cn.testquestion;
import java.io.*;
public class StudentGrate
{
public static void main(String args[])throws Exception
{
Student[] student={
new Student("10001","LiNing",88,99,68),
new Student("10002","LiLie",80,79,85),
new Student("10003","YunFei",88,90,67),
new Student("10004","ChunLi",55,91,73),
new Student("10005","ZhangSan",96,80,75)
};
/*
Student student1=new Student("10001","LiNing",88,99,68);
Student student2=new Student("10002","LiLie",80,79,85);
Student student3=new Student("10003","YunFei",88,90,67);
Student student4=new Student("10004","ChunLi",55,91,73);
Student student5=new Student("10005","ZhangSan",96,80,75);
*/
for(int i=0;i<student.length;i++)
{
new FileStudent(student[i]).toFileIn();
}
}
}
class Student
{
private String xuehao;
private String name;
private int shuxue;
private int yuwen;
private int yingyu;
private int average;
public Student(String xuehao,String name,int shuxue,int yuwen,int yingyu)
{
this.xuehao=xuehao;
this.name=name;
this.shuxue=shuxue;
this.yuwen=yuwen;
this.yingyu=yingyu;
this.average=(this.shuxue+this.yuwen+this.yingyu)/3;
}
public String toString()
{
String nextline=System.getProperty("line.separator"); return "学号:"+this.xuehao+" 姓名:"+this.name+" 数学成绩:"+this.shuxue+" 语文成绩:"+this.yuwen+" 英语成绩:"+this.yingyu+" 平均成绩:"+this.average+nextline;
}
}
class FileStudent
{
private static String str="";
private Student person;
public FileStudent(Object person)
{
this.person=(Student)person;
}
public void toFileIn()throws Exception
{
//String str="";
File file=new File("stud.txt");
if(!file.exists())
file.createNewFile();
//else
// System.out.println("文件已经存在。。。");
FileWriter fileto=new FileWriter(file);
str=str+person.toString();
fileto.write(str);
fileto.close();
}
}
package test;
import java.io.*;
public class Test
{
public static void main(String args[])throws Exception
{
Student[] student={
new Student("10001","LiNing",88,99,68),
new Student("10002","LiLie",80,79,85),
new Student("10003","YunFei",88,90,67),
new Student("10004","ChunLi",55,91,73),
new Student("10005","ZhangSan",96,80,75)
};
/*
Student student1=new Student("10001","LiNing",88,99,68);
Student student2=new Student("10002","LiLie",80,79,85);
Student student3=new Student("10003","YunFei",88,90,67);
Student student4=new Student("10004","ChunLi",55,91,73);
Student student5=new Student("10005","ZhangSan",96,80,75);
*/
for(int i=0;i<student.length;i++)
{
new FileStudent(student[i]).toFileIn();
}
}
}
class Student
{
private String xuehao;
private String name;
private int shuxue;
private int yuwen;
private int yingyu;
private int average;
public Student(String xuehao,String name,int shuxue,int yuwen,int yingyu)
{
this.xuehao=xuehao;
this.name=name;
this.shuxue=shuxue;
this.yuwen=yuwen;
this.yingyu=yingyu;
this.average=(this.shuxue+this.yuwen+this.yingyu)/3;
}
public String toString()
{
return "学号:\n"+this.xuehao+" 姓名:\n"+this.name+" 数学成绩:\n"+this.shuxue+" 语文成绩:\n"+this.yuwen+" 英语成绩:"+this.yingyu+" 平均成绩:"+this.average+" === ";
}
}
class FileStudent
{
private static String str="";
private Student person;
public FileStudent(Object person)
{
this.person=(Student)person;
}
public void toFileIn()throws Exception
{
//String str="";
File file=new File("stud.txt");
if(!file.exists())
file.createNewFile();
//else
// System.out.println("文件已经存在。。。");
FileWriter fileto=new FileWriter(file);
str=str+person.toString();
fileto.write(str);
fileto.close();
}
}
这个是文件内容
学号:
10001 姓名:
LiNing 数学成绩:
88 语文成绩:
99 英语成绩:68 平均成绩:85 === 学号:
10002 姓名:
LiLie 数学成绩:
80 语文成绩:
79 英语成绩:85 平均成绩:81 === 学号:
10003 姓名:
YunFei 数学成绩:
88 语文成绩:
90 英语成绩:67 平均成绩:81 === 学号:
10004 姓名:
ChunLi 数学成绩:
55 语文成绩:
91 英语成绩:73 平均成绩:73 === 学号:
10005 姓名:
ZhangSan 数学成绩:
96 语文成绩:
80 英语成绩:75 平均成绩:83 ===