凑合着看
package rw;
import java.io.*;
/*有五个学生,每个学生有3门课的成绩,定义一种比较直观的文本文件格式,
输入学生姓名和成绩,从键盘输入以上数据(包括姓名,三门课成绩),
按总分数从高到低的顺序将学生信息存放在磁盘文件"stu.txt"中。*/
public class Stundent {
private Integer Math; //数学成绩
private Integer Java; //java课程成绩
private Integer English; //英语成绩
private int i;
StringBuffer sb = new StringBuffer();;
public StringBuffer getCourst(int Math, int Java, int English, int i)
{
this.Math = Math;
this.Java = Java;
this.English = English;
this.i = i;
//将整形转化成一个字符串
sb.append(Integer.toString(Math) + " ").append(Integer.toString(Java) + " ").append(Integer.toString(English)).append("\r\n");
System.out.println(sb);
return sb;
}
public void Writer()
{
String str1;
String str;
str1 = "Math Java English"; //科目
try {
FileWriter fw = new FileWriter("D:\\stu.txt");
BufferedWriter bw = new BufferedWriter(fw);
bw.write(str1);
bw.newLine();
bw.write(sb.toString());
bw.flush();
// System.out.println(i);
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package rw;
public class test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Stundent s = new Stundent();
s.getCourst(100, 99, 80, 1);
s.getCourst(100, 90, 88, 2);
s.getCourst(100, 10, 88, 3);
s.getCourst(100, 10, 70, 4);
s.getCourst(130, 10, 88, 5);
s.Writer();
}
}
|