A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© lwj123   /  2015-5-15 19:21  /  33290 人查看  /  410 人回复  /   2 人收藏 转载请遵从CC协议 禁止商业使用本文

public class Student {
        private String name;
        private int age;
        private int score;

        public Student() {
                super();

        }

        public Student(String name, int age, int score) {
                super();
                this.name = name;
                this.age = age;
                this.score = score;
        }

        public String getName() {
                return name;
        }

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

        public int getAge() {
                return age;
        }

        public void setAge(int age) {
                this.age = age;
        }

        public int getScore() {
                return score;
        }

        public void setScore(int score) {
                this.score = score;
        }

        public String toString() {
                return "Student [name=" + name + ", age=" + age + ", score=" + score
                                + "]";
        }

}


public class Test_SelectSort {
        public static void main(String[] args) {
                TreeSet<Student> ts = new TreeSet<>(new Comparator<Student>() {
                        public int compare(Student s1, Student s2) {
                                int score = s2.getScore() - s1.getScore();
                                int age = score == 0? s1.getAge() - s2.getAge() : score;
                                return age == 0? s1.getName().compareTo(s2.getName()) : age;
                        }
                });

                ts.add(new Student("Tom", 24, 89));
                ts.add(new Student("Robin", 32, 99));
                ts.add(new Student("Jerry", 24, 99));
                ts.add(new Student("Lili", 23, 87));
                ts.add(new Student("Jack", 22, 87));
                ts.add(new Student("Lilei", 25, 95));
                ts.add(new Student("Robin", 32, 99));

                for (Student student : ts) {
                        System.out.println(student);
                }
        }

}
回复 使用道具 举报
还有吗??????
回复 使用道具 举报
来晚了,活动结束了
回复 使用道具 举报
注意:答题一律往答题区回帖,本贴只限回帖领题!
回复 使用道具 举报
让我看看题目
回复 使用道具 举报
试一试 看看能做出来不
回复 使用道具 举报
领题了。。。。。。
回复 使用道具 举报
1900 来自手机 中级黑马 2016-2-25 17:33:42
388#
速速前来
回复 使用道具 举报
赞                                                        
回复 使用道具 举报
看看有多难!
回复 使用道具 举报
看看。。。。
回复 使用道具 举报
活动已结束,谢谢大家的捧场
回复 使用道具 举报
活动已结束,谢谢大家的捧场
回复 使用道具 举报
回复的淡淡的淡淡的淡淡的淡淡的淡淡的淡淡的淡淡的淡淡的淡淡的淡淡的淡淡的淡淡的淡淡的淡淡的淡淡的淡淡的
回复 使用道具 举报
赶紧看看自己的水平
回复 使用道具 举报
俺来看看
回复 使用道具 举报
过来这边领题
回复 使用道具 举报
速看,快点来
回复 使用道具 举报
a382541804 来自手机 中级黑马 2016-4-9 22:08:22
399#
看下是什么题目
回复 使用道具 举报
来练练手
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马