数据结构-排序(选做)

程序代码:

Student.

class Student{
    private String id;//表示学号
    private String name;//表示姓名
    private int age;//表示年龄
    private char sex;//表示性别
    private double computer_score;//表示计算机课程的成绩
    private double english_score;//表示英语课的成绩
    private double maths_score;//表示数学课的成绩
    private double total_score;// 表示总成绩
    private double ave_score; //表示平均成绩
    public Student(String id, String name){
        this.id = id;
        this.name = name;
    }
    public Student(String id, String name, char sex, int age,
                   double computer_score,double english_score,double maths_score){
        this(id, name);
        this.sex = sex;
        this.age = age;
        this.computer_score=computer_score;
        this.english_score=english_score;
        this.maths_score=maths_score;
    }
    public String getId(){
        return id;
    }//获得当前对象的学号,
    public double getComputer_score(){
        return computer_score;
    }//获得当前对象的计算机课程成绩,
    public double getMaths_score(){
        return maths_score;
    }//获得当前对象的数学课程成绩,
    public double getEnglish_score(){
        return english_score;
    }//获得当前对象的英语课程成绩,

    public void setId(String id){
        this.id=id;
    }// 设置当前对象的id值,
    public void setComputer_score(double computer_score){
        this.computer_score=computer_score;
    }//设置当前对象的Computer_score值,
    public void setEnglish_score(double english_score){
        this.english_score=english_score;
    }//设置当前对象的English_score值,
    public void setMaths_score(double maths_score){
        this.maths_score=maths_score;
    }//设置当前对象的Maths_score值,

    public double getTotalScore(){
        return computer_score+maths_score+english_score;
    }// 计算Computer_score, Maths_score 和English_score 三门课的总成绩。
    public double getAveScore(){
        return getTotalScore()/3;
    }// 计算Computer_score, Maths_score 和English_score 三门课的平均成绩。
    @Override
    public String toString(){
        total_score=getTotalScore();
        return "Student[姓名:"+name+",学号:"+id+",总成绩:"+total_score+"]";
    }
}

StudentSortID

1602685-20190505232859701-1977144777.png

StudentSortMark

1602685-20190505232922096-1750471916.png

ComparatorByID

1602685-20190505232939327-1056254339.png

ComparatorByMark

1602685-20190505233004768-323403060.png

运行截图:

StudentSortID

1602685-20190505233054279-495732562.png

StudentSortMark

1602685-20190505233123216-918561927.png

转载于:https://www.cnblogs.com/LZHNB/p/10817150.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值