誰拿的獎金比較多

某校的慣例是在每學(xué)期的期末考試之后發(fā)放獎學(xué)金。發(fā)放的獎學(xué)金共有五種,獲取的條件各自不同:

院士獎學(xué)金,每人8000元,期末平均成績高于80分(>80),并且在本學(xué)期內(nèi)發(fā)表1篇或1篇以上論文的學(xué)生均可獲得;
五四獎學(xué)金,每人4000元,期末平均成績高于85分(>85),并且班級評議成績高于80分(>80)的學(xué)生均可獲得;
成績優(yōu)秀獎,每人2000元,期末平均成績高于90分(>90)的學(xué)生均可獲得;
西部獎學(xué)金,每人1000元,期末平均成績高于85分(>85)的西部省份學(xué)生均可獲得;
班級貢獻獎,每人850元,班級評議成績高于80分(>80)的學(xué)生干部均可獲得;
只要符合條件就可以得獎,每項獎學(xué)金的獲獎人數(shù)沒有限制,每名學(xué)生也可以同時獲得多項獎學(xué)金。例如姚林的期末平均成績是87分,班級評議成績82分,同時他還是一位學(xué)生干部,那么他可以同時獲得五四獎學(xué)金和班級貢獻獎,獎金總數(shù)是4850元。
基本要求

現(xiàn)在給出若干學(xué)生的相關(guān)數(shù)據(jù),請計算哪些同學(xué)獲得的獎金總數(shù)最高(假設(shè)總有同學(xué)能滿足獲得獎學(xué)金的條件)。
輸入數(shù)據(jù)格式格式:
輸入的第一行是一個整數(shù)N(1 <= N <= 100),表示學(xué)生的總數(shù)。接下來的N行每行是一位學(xué)生的數(shù)據(jù),從左向右依次是姓名,期末平均成績,班級評議成績,是否是學(xué)生干部,是否是西部省份學(xué)生,以及發(fā)表的論文數(shù)。姓名是由大小寫英文字母組成的長度不超過20的字符串(不含空格);期末平均成績和班級評議成績都是0到100之間的整數(shù)(包括0和100);是否是學(xué)生干部和是否是西部省份學(xué)生分別用一個字符表示,Y表示是,N表示不是;發(fā)表的論文數(shù)是0到10的整數(shù)(包括0和10)。每兩個相鄰數(shù)據(jù)項之間用一個空格分隔。
輸出數(shù)據(jù)格式:
輸出包括三行,第一行是獲得最多獎金的學(xué)生的姓名,第二行是這名學(xué)生獲得的獎金總數(shù)。如果有兩位或兩位以上的學(xué)生獲得的獎金最多,輸出他們之中在輸入文件中出現(xiàn)最早的學(xué)生的姓名。第三行是這N個學(xué)生獲得的獎學(xué)金的總數(shù)。

輸入

4
YaoLin 87 82 Y N 0
ChenRuiyi 88 78 N Y 1
LiXin 92 88 N N 0
ZhangQin 83 87 Y N 1

輸出

ChenRuiyi
9000
28700

main函數(shù)

package hello;

import java.util.*;

public class Scholarship {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        System.out.println("請輸入學(xué)生個數(shù)和" +
                "學(xué)生信息:(學(xué)生姓名 平均成績 評議成績 是否為干部 是否為西部省份學(xué)生 寫過幾篇論文)");
        List<Student> studentList=new ArrayList<Student>();
        String inputCount=scanner.nextLine();
        int inputCount2=Integer.parseInt(inputCount);
        for(int i=0;i<inputCount2;i++)
        {
            String input=scanner.nextLine();
            String[] info=input.split(" ");
            int avgScore=Integer.parseInt(info[1]);
            int dayScore=Integer.parseInt(info[2]);
            int paperCount=Integer.parseInt(info[5]);
            boolean isCadre=false;
            boolean isWest=false;
            if(info[3].equals("Y"))
            {
                isCadre=true;
            }
            else {
                isCadre=false;
            }
            if(info[4].equals("Y"))
            {
                isWest=true;
            }
            else {
                isWest=false;
            }
            Student student=new Student(info[0],avgScore,dayScore,isCadre,isWest,paperCount);
            studentList.add(student);
        }
        for(Student student:studentList)
        {
            int sum=0;
            if(student.getAvgScore()>80&&student.getPaperCount()>=1)
            {
                sum+=8000;
            }
            if(student.getAvgScore()>85&&student.getDayScore()>80)
            {
                sum+=4000;
            }
            if(student.getAvgScore()>90)
            {
                sum+=2000;
            }
            if(student.getAvgScore()>85&&student.isWest()==true)
            {
                sum+=1000;
            }
            if(student.getAvgScore()>80&&student.isCadre()==true)
            {
                sum+=850;
            }
            student.setScholarship(sum);
        }
        List<Student> oldStudentList=new ArrayList<Student>();
        for(Student student:studentList)
        {
            oldStudentList.add(student);
        }
        Collections.sort(studentList);
        Set<Student> maxScholarshipStudent=new HashSet<Student>();
        for(int i=0;i<studentList.size();i++)
        {
            if(i==studentList.size()-1)
            {
                break;
            }
            else if(studentList.get(i).getScholarship()==studentList.get(i+1).getScholarship())
            {
                maxScholarshipStudent.add(studentList.get(i));
                maxScholarshipStudent.add(studentList.get(i+1));
            }
        }
        if(maxScholarshipStudent.size()==0)
        {
            maxScholarshipStudent.add(studentList.get(0));
        }
        int sum=0;
        for(Student student:maxScholarshipStudent)
        {
            sum+=student.getScholarship();
        }
        Student outputStudent=new Student();
        for(Student student:oldStudentList)
        {
            if(maxScholarshipStudent.contains(student))
            {
                outputStudent=student;
                break;
            }
        }
        System.out.println("獎學(xué)金最多的人是"+outputStudent.getName());
        System.out.println("獎學(xué)金是"+outputStudent.getScholarship());
        if(maxScholarshipStudent.size()>1)
        {
            System.out.println("總獎金為"+sum+"元");
        }
    }
}

Student類

package hello;

public class Student implements Comparable{
    private String name;
    private int avgScore;
    private int dayScore;
    private boolean isCadre;
    private boolean isWest;
    private int paperCount;
    private int scholarship;

    public Student(){

    }

    public Student(String name, int avgScore, int dayScore, boolean isCadre, boolean isWest, int paperCount) {
        this.name = name;
        this.avgScore = avgScore;
        this.dayScore = dayScore;
        this.isCadre = isCadre;
        this.isWest = isWest;
        this.paperCount = paperCount;
    }

    public String getName() {
        return name;
    }

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

    public int getAvgScore() {
        return avgScore;
    }

    public void setAvgScore(int avgScore) {
        this.avgScore = avgScore;
    }

    public int getDayScore() {
        return dayScore;
    }

    public void setDayScore(int dayScore) {
        this.dayScore = dayScore;
    }

    public boolean isCadre() {
        return isCadre;
    }

    public void setCadre(boolean cadre) {
        isCadre = cadre;
    }

    public boolean isWest() {
        return isWest;
    }

    public void setWest(boolean west) {
        isWest = west;
    }

    public int getPaperCount() {
        return paperCount;
    }

    public void setPaperCount(int paperCount) {
        this.paperCount = paperCount;
    }

    public int getScholarship() {
        return scholarship;
    }

    public void setScholarship(int scholarship) {
        this.scholarship = scholarship;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", avgScore=" + avgScore +
                ", dayScore=" + dayScore +
                ", isCadre=" + isCadre +
                ", isWest=" + isWest +
                ", paperCount=" + paperCount +
                ", scholarship=" + scholarship +
                '}';
    }

    @Override
    public int compareTo(Object o) {
        Student student=(Student)o;
        return student.getScholarship()-this.getScholarship();
    }
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容