学号 姓名 语文 数学 英语 总值 平均值 排序
1 李守东 83 73 75 231 77.0 0
2 徐贤坤 58 58 87 203 67.0 0
3 钱云宋 41 86 90 217 72.0 0
4 陈平 83 43 65 191 63.0 0
5 金荣权 93 88 63 244 81.0 0
6 陈如棉 99 93 43 235 78.0 0
7 章可可 98 62 72 232 77.0 0
8 陈伟奔 87 43 76 206 68.0 0
9 张如祥 69 58 78 205 68.0 0
10 丁尚游 80 56 57 193 64.0 0
11 林宏旦 91 90 76 257 85.0 0
12 曾上腾 100 96 54 250 83.0 0
13 谢作品 82 100 55 237 79.0 0
14 温从卫 73 46 101 220 73.0 0
15 李明察 81 41 75 197 65.0 0
16 彭鸿威 46 46 89 181 60.0 0
17 翁文秀 57 43 58 158 52.0 0
18 陈家伟 63 58 98 219 73.0 0
19 温正考 100 64 57 221 73.0 0
20 周文湘 50 50 79 179 59.0 0
21 吴杰 65 65 83 213 71.0 0
22 赖登城 60 79 53 192 64.0 0
23 聂树露 51 76 45 172 57.0 0
24 张雅琴 68 95 56 219 73.0 0
25 曾瑞约 88 63 58 209 69.0 0
26 王志强 96 79 78 253 84.0 0
27 徐贤所 66 46 74 186 62.0 0
28 陈祥枭 82 96 91 269 89.0 0
29 温婷婷 41 73 96 210 70.0 0
30 应孔余 66 81 71 218 72.0 0
31 宋成取 71 68 62 201 67.0 0
32 黄益省 65 56 43 164 54.0 0
33 陈思文 55 100 44 199 66.0 0
34 上官福新 64 62 70 196 65.0 0
35 钟国横 49 69 56 174 58.0 0
36 林型涨 78 73 50 201 67.0 0
学号 姓名 语文 数学 英语 总值 平均值 排序
1 李守东 83 73 75 231 77.0 9
2 徐贤坤 58 58 87 203 67.0 21
3 钱云宋 41 86 90 217 72.0 15
4 陈平 83 43 65 191 63.0 29
5 金荣权 93 88 63 244 81.0 5
6 陈如棉 99 93 43 235 78.0 7
7 章可可 98 62 72 232 77.0 8
8 陈伟奔 87 43 76 206 68.0 19
9 张如祥 69 58 78 205 68.0 20
10 丁尚游 80 56 57 193 64.0 27
11 林宏旦 91 90 76 257 85.0 2
12 曾上腾 100 96 54 250 83.0 4
13 谢作品 82 100 55 237 79.0 6
14 温从卫 73 46 101 220 73.0 11
15 李明察 81 41 75 197 65.0 25
16 彭鸿威 46 46 89 181 60.0 31
17 翁文秀 57 43 58 158 52.0 36
18 陈家伟 63 58 98 219 73.0 12
19 温正考 100 64 57 221 73.0 10
20 周文湘 50 50 79 179 59.0 32
21 吴杰 65 65 83 213 71.0 16
22 赖登城 60 79 53 192 64.0 28
23 聂树露 51 76 45 172 57.0 34
24 张雅琴 68 95 56 219 73.0 13
25 曾瑞约 88 63 58 209 69.0 18
26 王志强 96 79 78 253 84.0 3
27 徐贤所 66 46 74 186 62.0 30
28 陈祥枭 82 96 91 269 89.0 1
29 温婷婷 41 73 96 210 70.0 17
30 应孔余 66 81 71 218 72.0 14
31 宋成取 71 68 62 201 67.0 22
32 黄益省 65 56 43 164 54.0 35
33 陈思文 55 100 44 199 66.0 24
34 上官福 64 62 70 196 65.0 26
35 钟国横 49 69 56 174 58.0 33
36 林型涨 78 73 50 201 67.0 23
package com.company;
public class student implements Comparable {
private int stunum;
private String name;
private int chinesescore;
private int mathscore;
private int englishscore;
private int totalscore;
private double avgscore;
private int rank;
@Override
public String toString() {
return "" +
stunum +"\t"+
name + "\t"+
chinesescore +"\t"+
mathscore +"\t"+
englishscore +"\t"+
totalscore +"\t"+
avgscore +"\t"+
rank
;
}
public int totalcalc(){
int total = 0;
total = this.chinesescore + this.mathscore+this.englishscore;
this.totalscore = total;
return total;
}
public double avgcalc(){
double avg = 0;
avg = totalcalc()/3;
this.avgscore = avg;
return avg;
}
public int getStunum() {
return stunum;
}
public void setStunum(int stunum) {
this.stunum = stunum;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getChinesescore() {
return chinesescore;
}
public void setChinesescore(int chinesescore) {
this.chinesescore = chinesescore;
}
public int getMathscore() {
return mathscore;
}
public void setMathscore(int mathscore) {
this.mathscore = mathscore;
}
public int getEnglishscore() {
return englishscore;
}
public void setEnglishscore(int englishscore) {
this.englishscore = englishscore;
}
public int getTotalscore() {
return totalscore;
}
public void setTotalscore(int totalscore) {
this.totalscore = totalscore;
}
public double getAvgscore() {
return avgscore;
}
public void setAvgscore(double avgscore) {
this.avgscore = avgscore;
}
public int getRank() {
return rank;
}
public void setRank(int rank) {
this.rank = rank;
}
@Override
public int compareTo(Object o) {
student student = (student)o;
return student.totalscore - this.totalscore;
}
}
package com.company;
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
// write your code here
FileReader fileReader = new FileReader("d:/student.txt");
BufferedReader bufferedReader = new BufferedReader(fileReader);
List<student> studentList = new ArrayList<>();
bufferedReader.readLine();
String str = bufferedReader.readLine();
while (str != null){
student student = new student();
List<String> stringList = new ArrayList<>();
String[] strings = str.split(" ");
for (String string:strings){
if (!string.equals("")){
stringList.add(string);
}
}
if (stringList.size() > 0){
student.setStunum(Integer.valueOf(stringList.get(0)));
student.setName(stringList.get(1));
student.setChinesescore(Integer.valueOf(stringList.get(2)));
student.setMathscore(Integer.valueOf(stringList.get(3)));
student.setEnglishscore(Integer.valueOf(stringList.get(4)));
studentList.add(student);
}
str = bufferedReader.readLine();
}
for (student student:studentList){
student.avgcalc();
}
List<student> studentListNew = new ArrayList<>();
studentListNew.addAll(studentList);
Collections.sort(studentListNew);
for (int i = 0;i< studentListNew.size(); i++){
student student = studentListNew.get(i);
student.setRank(i+1);
}
File file = new File("d:/new_student.txt");
Writer writer = new FileWriter(file);
BufferedWriter bufferedWriter = new BufferedWriter(writer);
bufferedWriter.write("学号\t姓名\t语文\t数学\t英语\t总值\t平均值\t排序");
bufferedWriter.newLine();
for (student student:studentList){
bufferedWriter.write(student.toString());
bufferedWriter.newLine();
}
bufferedReader.close();
bufferedWriter.close();
}
}
网友评论