(java)编写一个学生成绩分析程序

(java)编写一个学生成绩分析程序,学生成绩由文件输入获取,每个学生成绩包括学号、姓名、数学、物理、英语。一个学生数据占1行。数据导入到数组列表中。1)按总分由高到低排... (java) 编写一个学生成绩分析程序,学生成绩由文件输入获取,每个学生成绩包括学号、姓名、数学、物理、英语。一个学生数据占1行。数据导入到数组列表中。
1)按总分由高到低排序输出;Integer.parseInt(str)
2)统计数学不及格学生人数。

求详细代码
展开
 我来答
罪love王子
2019-06-01 · TA获得超过124个赞
知道小有建树答主
回答量:123
采纳率:80%
帮助的人:61.5万
展开全部
//学生类
public class Student {
private String NO;
private String name;
private int math;
private int physics;
private int english;
private int total = 0;
public Student(String NO, String name, int math, int physics, int english) {
this.NO = NO;
this.name = name;
this.math = math;
this.physics = physics;
this.english = english;
total = math + physics + english;
}
public String getNO() {
return NO;
}
public void setNO(String nO) {
NO = nO;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getMath() {
return math;
}
public void setMath(int math) {
this.math = math;
}
public int getPhysics() {
return physics;
}
public void setPhysics(int physics) {
this.physics = physics;
}
public int getEnglish() {
return english;
}
public void setEnglish(int english) {
this.english = english;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
@Override
public String toString() {
return "[学号=" + NO + ", 姓名=" + name + ", 数学成绩=" + math + ", 物理成绩=" + physics + ", 英语="
+ english + ", 总分=" + total + "]";
}


}

//排序
public static class CompareStudent implements Comparator<Student>{

@Override
public int compare(Student o1, Student o2) {

return o1.getTotal() < o2.getTotal() ? 1 : o1.getTotal() == o2.getTotal() ? 0 : -1;
}

}

public class Test {

public static void main(String[] args) {
String filename = "res/student.txt";
System.out.println("读取" + filename + "文件的数据");
List<Student> result = readStudnetInfoFromFile(filename);

//排序
result.sort(new CompareStudent());

System.out.println("排序输出");
for (Student student : result) {
System.out.println(student);
}
System.out.println();
//不及格
System.out.println("数学不及格");
int nums = 0;
for (Student student : result) {
if(student.getMath() < 60) {
System.out.println(student.getName() + " 数学成绩不及格");
nums ++;
}
}
System.out.println("数学不及格总共有" + nums + "人");
}



//从文件中读取数据
private static List<Student> readStudnetInfoFromFile(String filename) {
File file = new File(filename);
if (!file.exists()) {
return null;
}
List<Student> result = new ArrayList<>();
BufferedReader br = null;
FileReader fr = null;
try {
fr = new FileReader(file);
br = new BufferedReader(fr);
String line = null;
while ((line = br.readLine()) != null) {
String[] infos = line.split("_");
Student stu = new Student(infos[0], infos[1], Integer.parseInt(infos[2]), Integer.parseInt(infos[3]),
Integer.parseInt(infos[4]));
result.add(stu);
}

} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {

try {
if (br != null) {
br.close();
}
if(fr != null) {
fr.close();
}
} catch (IOException e) {
e.printStackTrace();
}

}

return result;
}


//数据文件  注意文件路径
1_张三_60_70_80
2_李四_58_58_73
3_王二_63_75_85
4_莉莉_46_75_88
5_小明_85_76_56
帐号已注销
2019-06-01 · TA获得超过168个赞
知道答主
回答量:589
采纳率:18%
帮助的人:62.4万
展开全部
又不是很难 自己不会吗?
追问
自己自学,不太会的
追答
呃呃呃  虽然不是很难  但是也费时间
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式