日期:2014-05-20 浏览次数:20804 次
/**
* <pre>
* @author kanpiaoxue
* Date 2013-11-27
* </pre>
*/
public class Student {
private String name;
private int age;
private double javaScore;
private double cScore;
public Student() {
super();
}
public Student(String name, int age, double javaScore, double cScore) {
super();
this.name = name;
this.age = age;
this.javaScore = javaScore;
this.cScore = cScore;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getJavaScore() {
return javaScore;
}
public void setJavaScore(double javaScore) {
this.javaScore = javaScore;
}
public double getCScore() {
return cScore;
}
public void setCScore(double cScore) {
this.cScore = cScore;
}
}
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.IOUtils;
import com.alibaba.fastjson.JSON;
/**
* <pre>
* @author kanpiaoxue
* Date 2013-11-27
* </pre>
*/
public class TestChengji {
private static final String DATA_FILE = "D:\\tmp\\students.txt";
/**
* <pre>
* 连续提问学生的姓名,年龄,java成绩,C成绩。当输入stop的时候,结束,并计算结果
* </pre>
*
* @throws Exception
*/
public static void main(String[] args) throws Exception {
TestChengji t = new TestChengji();
List<Student> students = t.createStudents();
t.saveStudentsToFile(students);
students = t.readStudentsFromFile();
t.calculateStudents(students);
/**
* <pre>
*
* 下面是程序的运行结果:
*
* Please enter student name :student1
* Please enter student age :20
* Please enter student java score :98
* Please enter student C score :89
* Do you continue enter student infomation? (yes/no) : yes
* Please enter student name :student2
* Please enter student age :20
* Please enter student java score :90
* Please enter student C score :88
* Do you continue enter student infomation? (yes/no) : yes
* Please enter student name :student3
* Please enter student age :20
* Please enter student java score :85
* Please enter student C score :85
* Do you continue enter student infomation? (yes/no) : no
* stop enter students infomation.
* write datas to D:\tmp\students.txt successfully!