package homework;/*** @author Alina* @date 2021年09月22日 10:34 下午*/
class SetTestStudent implements Comparable<SetTestStudent>{private String name;private int gradeScoresOfChinese;private int gradeScoresOfMath;private int gradeScoresOfEnglish;public  int TotalScore(){return this.gradeScoresOfChinese+this.gradeScoresOfMath+this.gradeScoresOfEnglish;}public int compareTo(SetTestStudent s){int Score =   s.TotalScore() - this.TotalScore();return Score==0? this.getName().compareTo(s.getName()):Score;}public String toString(){return "name : "+getName()+"  "+"chinese: "+getGradeScoresOfChinese()+"  "+"math: "+getGradeScoresOfMath()+ "  "+"english: "+getGradeScoresOfEnglish();}public SetTestStudent(String name, int gradeScoresOfChinese, int gradeScoresOfMath, int gradeScoresOfEnglish) {this.name = name;this.gradeScoresOfChinese = gradeScoresOfChinese;this.gradeScoresOfMath = gradeScoresOfMath;this.gradeScoresOfEnglish = gradeScoresOfEnglish;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getGradeScoresOfChinese() {return gradeScoresOfChinese;}public void setGradeScoresOfChinese(int gradeScoresOfChinese) {this.gradeScoresOfChinese = gradeScoresOfChinese;}public int getGradeScoresOfMath() {return gradeScoresOfMath;}public void setGradeScoresOfMath(int gradeScoresOfMath) {this.gradeScoresOfMath = gradeScoresOfMath;}public int getGradeScoresOfEnglish() {return gradeScoresOfEnglish;}public void setGradeScoresOfEnglish(int gradeScoresOfEnglish) {this.gradeScoresOfEnglish = gradeScoresOfEnglish;}
}
package homework;import java.util.*;/*** @author Alina* @date 2021年09月22日 10:21 上午**/
public class SetTest {public static void main(String[] args) {method_3();}public static void method_3(){Scanner sc = new Scanner(System.in);TreeSet< SetTestStudent> t = new TreeSet<>();for (int x= 0;x<5;x++){String StudentInformation = sc.nextLine();String[]studentInformation = StudentInformation.split(" +");t.add(new SetTestStudent(studentInformation[0],Integer.parseInt(studentInformation[1]),Integer.parseInt(studentInformation[2]),Integer.parseInt(studentInformation[3])));}for(SetTestStudent s :t ){System.out.println(s);}}/***** 键盘录入五个学生信息(姓名,语文成绩,数学成绩,英语成绩)按照总分的高低输出*/public static void method_2() {TreeSet<SetTestStudent> stu = new TreeSet<>();for (int x = 0; x < 5; x++) {System.out.println("please input your name:");String StudentName = (new Scanner(System.in)).nextLine();System.out.println("Please enter your Chinese score:");int ScoresOfChinese = (new Scanner(System.in)).nextInt();System.out.println("Please enter your Math score:");int ScoresOfMath = (new Scanner(System.in)).nextInt();System.out.println("Please enter your English score:");int ScoresOfEnglish = (new Scanner(System.in)).nextInt();SetTestStudent stfg = new SetTestStudent(StudentName, ScoresOfChinese, ScoresOfMath, ScoresOfEnglish);stu.add(stfg);}Iterator it = stu.iterator();while (it.hasNext()) {System.out.println(it.next());}}/**** @author Alina* @date 2021/9/22 10:30 下午* 生成10个20以内的随机数,要求不能重复*/public static void method_1(){TreeSet<Integer> t = new TreeSet<>();Random r = new Random();while (true) {if (t.size() <= 10) {int num = r.nextInt(100) + 1;t.add(num);} else {System.out.println(t);break;}}}
}

(JAVA)TreeSet相关推荐

  1. 赵栋/东文才 《面向对象程序设计(java)》第十一周学习总结

    201771010137 赵栋<面向对象程序设计(java)>第十一周学习总结 一:理论部分. 1.数据结构:分为a.线性数据结构,如线性表.栈.队列.串.数组和文件. b.非线性数据结构 ...

  2. 东文财、赵栋《面向对象程序设计(java)》第十一周学习总结

    201771010106 东文财<面向对象程序设计(java)>第十一周 实验时间 2018-11-8 一:理论部分. 1.数据结构: a.线性数据结构,如线性表.栈.队列.串.数组和文件 ...

  3. 动物专家识别系统(Java)

    动物专家识别系统(Java) 一·专家系统 二·产生式规则 2.1概念 2.2原理 2.3原理图示 三·设计思路 3.1规则文档 3.1.1识别动物种类 3.1.2Rule 3.2设计类 3.3设计规 ...

  4. 常惠琢 201771010102《面向对象程序设计(java)》第七周学习总结

    实验七 继承附加实验 实验时间 2018-10-11 1.实验目的与要求 (1)进一步理解4个成员访问权限修饰符的用途: (2)掌握Object类的常用API用法: (3)掌握ArrayList类用法 ...

  5. 建立与ftp服务器的连接——完成版(java)

    建立与ftp服务器的连接--完成版(java) // ftp 程序Ftp.java // 此程序的功能是建立与ftp服务器的连接并实现文件传输 // 使用方法:java Ftp 服务器地址 //启动示 ...

  6. 海康摄像头的二次开发(java)

    海康摄像头的二次开发(java) 我第一次接触海康摄像头的二次开发的项目,一开始的时候摸不清套路,走了不少弯路,现在准备把我的一些经验留下来,让大家参考一下. 1.首先到海康的官网下载设备网络SDK: ...

  7. 《编程导论(Java)#183;1.4.1 范式》

    这个楼主,是我的学生么?2013年写的! 嗯."编程范式或许是学习不论什么一门编程语言时要理解的最重要的术语".这句话早在2005年出版<Java程序设计>(宋中山,严 ...

  8. 201771010106东文财《面向对象程序设计(java)》实验12

    实验十二  图形程序设计 实验时间 2018-11-14 1.实验目的与要求 (1) 掌握Java GUI中框架创建及属性设置中常用类的API: (2) 掌握Java GUI中2D图形绘制常用类的AP ...

  9. 2018面向对象程序设计(Java)第3周学习指导及要求

    2018面向对象程序设计(Java) 第3周学习指导及要求(2018.9.11-2018.9.16)   学习目标 适应老师教学方式,能按照自主学习要求完成本周理论知识学习: 掌握Java Appli ...

最新文章

  1. 网络工程师人手必备!常用网络命令合集请收下
  2. 开始食用grpc(之一)
  3. c++基础学习(10)--(文件、流、异常处理、动态内存、命名空间)
  4. matlab中直到循环语句,Matlab再次执行循环,直到第一条语句结束
  5. php : Warning: strftime(): It is not safe to rely on the system's timezone settings.
  6. mysql tcp优化_mysql 优化
  7. python如何查看类信息_关于如何查看本地python类库详细信息的方法
  8. 规则引擎 drools_Drools的入门初探
  9. 基于python下django框架 实现校园二手书籍交易系统详细设计
  10. sensor 驱动调试小结
  11. NoteExpress的题录中文??问题
  12. 5.2 Photoshop复制图层的几种方式 [原创Ps教程]
  13. Matlab基于颜色的车牌识别
  14. python将多个列表合并_Python中多个列表与字典的合并方法
  15. python绘制语谱图(详细注释)
  16. C语言中的与、或、非
  17. 非华为手机Scrcpy无线投屏电脑多屏协同步骤(电脑无线连接投屏手机,设备,tcpip)
  18. java 万能解压zip工具类
  19. 深度森林deep-forest | ImportError: cannot import name ‘_joblib_parallel_args‘ from ‘sklearn.utils.fixes‘
  20. Maven 3-Maven依赖版本冲突的分析及解决小结 (阿里,美团,京东面试)

热门文章

  1. 前端学习(493):script之延迟脚本和异步脚本
  2. 前端学习(338):堆栈
  3. 63 javabean的作用域范围
  4. 玩转oracle 11g(8):使用profile管理用户口令
  5. 实例51:python
  6. STM32 FreeRTOS USART DMA空闲中断和消息队列的使用
  7. Github|基于 Jittor 的 GAN 模型库
  8. 集群没有leader_面试官问:说说你对ZooKeeper集群与Leader选举的理解?
  9. Winfrom窗体应用程序___DataGridView
  10. RTTI: dynamic_cast typeid