需求:
键盘录入5个学生信息(姓名,语文成绩,数学成绩,英语成绩),按照总分从高到低存入文本文件
分析:
A:创建学生类
B:创建集合对象
TreeSet<Student>
C:键盘录入学生信息存储到集合
D:遍历集合,把数据写到文本文件
首先创建个学生类
1 package zl_Test; 2 /** 3 * 这是个记录学生成绩类 4 * @author LZL 5 * 6 */ 7 public class Student { 8 private String name; 9 private int chinese; 10 private int math; 11 private int english; 12 13 14 public Student() { 15 super(); 16 // TODO Auto-generated constructor stub 17 } 18 19 20 public Student(String name, int chinese, int math, int english) { 21 super(); 22 this.name = name; 23 this.chinese = chinese; 24 this.math = math; 25 this.english = english; 26 } 27 28 29 public String getName() { 30 return name; 31 } 32 33 34 public void setName(String name) { 35 this.name = name; 36 } 37 38 39 public int getChinese() { 40 return chinese; 41 } 42 43 44 public void setChinese(int chinese) { 45 this.chinese = chinese; 46 } 47 48 49 public int getMath() { 50 return math; 51 } 52 53 54 public void setMath(int math) { 55 this.math = math; 56 } 57 58 59 public int getEnglish() { 60 return english; 61 } 62 63 64 public void setEnglish(int english) { 65 this.english = english; 66 } 67 68 public int getsum() { 69 return this.chinese + this.english + this.math; 70 71 72 } 73 74 }