(JAVA)TreeSet

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;}}}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/421757.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

开始

纠结的考试终于结束了。。。可以静下心来整理博客了。。。转载于:https://www.cnblogs.com/Happyhe/archive/2013/05/29/3107121.html

(JAVA)Map集合

package map.demo;import java.util.*;/*** author Alina* date 2021年09月25日 11:20 下午* 底层原理是哈希表&#xff0c;保证唯一性* 允许存储null键&#xff0c;null值* 线程不安全&#xff0c;运行速度快* keyset()可以获取到键* Collections 类的方法reverseOrder :调用空…

各种推荐资料汇总。。。

http://blog.csdn.net/lzt1983/article/details/7914536 转载于:https://www.cnblogs.com/tandychao/archive/2013/05/30/3108022.html

(JAVA)File类

package filedemo;import java.io.File; import java.io.IOException;/*** author Alina* date 2021年10月07日 10:33 下午* File类 提供方法操作 文件 目录 文件夹* 1.两个静态成员变量 static String pathSeparator 路径分隔符* 2.static String separator 名称分隔符* 3.创…

(JAVA)File类2

package filedemo;import java.io.File; import java.io.FileFilter; import java.text.DateFormat; import java.util.Date;/*** author Alina* date 2021年10月10日 11:15 下午* 1.获取文件最后修改时间 Long lastModified()* 2.以数组获取路径下所有文件String[] list();Fi…

MVVM之旅

MVVM的概念已经在脑子里渗透了一段时间&#xff0c;也试着使用了一段时间&#xff0c;就我个人理解&#xff0c;MVVM所倡导的应该是解耦UI跟数据打交道的那一部分&#xff0c;而纯UI的还是写在CodeBehind里。MVVM是以绑定&#xff08;绑定数据、绑定命令&#xff09;来驱动的&a…

变量原理深入讲解

javascript是一种解释执行的语言 语言分解释执行和编译执行 人用直观的编程语言来写程序-------------计算机语言010011100 举例理解&#xff1a; 英文 中国人张三(不会英文) 1、把英文报刊翻译成中文报刊&#xff0c;然后再看(翻译完后&#xff0c;多了一份中…

(JAVA)IO1

IO流四个抽象及类 1.字节输出流&#xff0c;写入任意文件OutputStreamwrite 字节数组 字节数组的一部分 单个字节close 释放资源flush 刷新资源&#xff0c;强制刷新资源 2.字节输入流&#xff0c;读取任意文件InputStreamread 字节数组 字节数组的一部分 单个字节close 关闭资…

putil:一个用于获得处理器和系统相关信息的模块

psutil能干的事是&#xff1a;提供了个接口&#xff0c;可以用来获取信息&#xff0c;包括&#xff1a; 当前运行的进程系统&#xff08;资源使用&#xff09;信息CPU内存磁盘网络用户psutil实现了很多功能&#xff0c;包括了如下工具所具有的&#xff1a; pstopdfkillfreelsof…

(JAVA)IO缓冲区

package IODemo;import java.io.*; import java.nio.charset.StandardCharsets;/*** author Alina* date 2021年10月18日 9:57 下午* 一、 1.IO流关于缓冲区&#xff0c;* 2.输出流缓冲区&#xff1a;BufferedOutputStream(OutputStream out)* 3.输入流缓冲区&#…

php正则表达式如何找到匹配模式中的最后一组

转载于:https://www.cnblogs.com/MyFlora/archive/2013/06/07/3124073.html

(JAVA)IO流之读写单个字节和复制文本文件

package IODemo;import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException;/*** author Alina* date 2021年10月15日 8:19 下午* read()方法特点* 1.每次只读取一个文件* 2.只运行一次&#xff0c…

sql where in 排序问题

直接上代码了 对于int类型的需要转化一下 select * from cvProducts where ID in(972,687,678,962) order by charindex(cast(ID as varchar),972,687,678,962) 对于varchar的直接使用 select * from cvProducts where MouldNo in(C62859,C63417,C32283) order by charindex(…