zoukankan      html  css  js  c++  java
  • java--学生排名

    package com.test;
    import com.bean.*;

    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Collection;
    import com.bean.Student;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Comparator;
    import java.util.HashSet;
    import java.util.LinkedHashSet;
    import java.util.List;
    import java.util.Random;
    import java.util.Scanner;
    import java.util.TreeSet;

    import com.bean.Student;
    public class test {

    //@SuppressWarnings({ "rawtypes", "unchecked" })
    
    
    
    public static void main(String[] args) {
    	//extracted_39();
    	Scanner sc =new Scanner(System.in);
    	System.out.println("please int:");
    	TreeSet<chengJi> ts =new TreeSet<>(new Comparator<chengJi>() {
    
    		@Override
    		public int compare(chengJi o1, chengJi o2) {
    			// TODO Auto-generated method stub
    			int num= o2.getSum()-o1.getSum();
    			return num==0? 1 :num;
    		}			
    	});
    	//录入五个学生
    	while(ts.size()<5) {
    		//将录入的字符串用逗号切割,返回同一个字符串数组,将字符串数组在二个元素转换成int数
    		String line =sc.nextLine();
    		String[] arr = line.split(",");
    		int chinese = Integer.parseInt(arr[1]);
    		int math = Integer.parseInt(arr[2]);
    		int english = Integer.parseInt(arr[3]);
    		//将装换后的结果封装成chengJi对象,将chengJi添加到TreeSet科技和中
    		ts.add(new chengJi(arr[0],chinese,math,english));
    	}
    		System.out.println("排序后的学生信息::");
    		for(chengJi c:ts) {
    			System.out.println(c);
    		}
    }
    

    public class chengJi {
    private String name;
    private int chinese;
    private int math;
    private int english;
    private int sum;
    public chengJi(String name, int chinese, int math, int english) {
    super();
    this.name = name;
    this.chinese = chinese;
    this.math = math;
    this.english = english;
    this.sum=this.chinese+this.english+this.math;
    }
    public chengJi() {
    super();
    // TODO Auto-generated constructor stub
    }
    public int getSum() {
    return sum;
    }
    public void setSum(int sum) {
    this.sum = sum;
    }
    @Override
    public String toString() {
    return name+","+chinese+english+math+sum;
    }

    }

    ******************************人因为有理想、梦想而变得伟大,而真正伟大就是不断努力实现理想、梦想*****************************
  • 相关阅读:
    Stepping Number
    Replace String
    String Permutation
    Clock Angle
    Keypad Permutation
    Replace Words
    1、奉加微 PHY6202 Get started
    Python3 修改二进制文件
    Google Fast Pair
    python 校验 BLE resolvable private address
  • 原文地址:https://www.cnblogs.com/cloudLi/p/13047743.html
Copyright © 2011-2022 走看看