创建多个类实现输入几个人按各科成绩由高到低排序

Employee.java

package test.score;

/**
 * @author U100926
 */
public class Employee {
    private String name;
    private int japanese;
    private int english;
    private int math;
    private int science;
    private int sociology;
    private int total;

    public Employee(String name, int japanese, int english, int math, int science, int sociology, int total) {
        this.name = name;
        this.japanese = japanese;
        this.english = english;
        this.math = math;
        this.science = science;
        this.sociology = sociology;
        this.total = total;
    }

    public String getName() {
        return name;
    }

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

    public int getJapanese() {
        return japanese;
    }

    public void setJapanese(int japanese) {
        this.japanese = japanese;
    }

    public int getEnglish() {
        return english;
    }

    public void setEnglish(int english) {
        this.english = english;
    }

    public int getMath() {
        return math;
    }

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

    public int getScience() {
        return science;
    }

    public void setScience(int science) {
        this.science = science;
    }

    public int getSociology() {
        return sociology;
    }

    public void setSociology(int sociology) {
        this.sociology = sociology;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }
}

Rank.java

package test.score;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Rank {
    public static void main(String[] args) {
        ArrayList<Employee> list = new ArrayList<>();
        list.add(new Employee("中島", 80, 90, 30, 50, 70, 320));
        list.add(new Employee("清水", 90, 94, 45, 50, 60, 339));
        list.add(new Employee("住石", 30, 40, 40, 100, 100, 310));
        list.add(new Employee("谷岡", 70, 40, 0, 100, 100, 310));
        rank(list);
    }
    private static void rank(ArrayList<Employee> list) {
        Collections.sort(list, new Comparator<Employee>() {
            @Override
            public int compare(Employee o1, Employee o2) {
                return o2.getTotal() - o1.getTotal();
            }
        });
        for (Employee e:list) {
            System.out.println(e.getName()+" "+e.getTotal());
        }
    }

}

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值