计算语文和数学成绩的总和java实现

在这里插入图片描述
Student

public class Student {
    private  String name;
    private  int yuwen;
    private int math;
    private int sum;

    public Student() {
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", yuwen=" + yuwen +
                ", math=" + math +
                ", sum=" + sum +
                '}';
    }

    public Student(String name, int yuwen, int math) {
        this.name = name;
        this.yuwen = yuwen;
        this.math = math;
        this.sum=yuwen+math;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getYuwen() {
        return yuwen;
    }

    public void setYuwen(int yuwen) {
        this.yuwen = yuwen;
    }

    public int getMath() {
        return math;
    }

    public void setMath(int math) {
        this.math = math;
    }

    public int getSum() {
        return sum;
    }

    public void setSum(int sum) {
        this.sum = sum;
    }
}
public class Sorce {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new FileReader("输入路径"));
        BufferedWriter bw = new BufferedWriter(new FileWriter("输出路径"));
        List<Student> list = new ArrayList<Student>();
        String line="";
        while ((line=br.readLine())!=null){
            String[] split = line.split(",");
            if (split.length>=3){
                Student student = new Student(split[0],Integer.valueOf(split[1]),Integer.valueOf(split[2]));
                list.add(student);
            }
        }
        Collections.sort(list, new Comparator<Student>() {
            public int compare(Student o1, Student o2) {
                return o1.getSum()>o2.getSum()?1:-1;
            }
        });
        for (Student s:list ) {
            bw.write(s.toString());
            bw.newLine();
        }
        bw.close();
        br.close();
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值