Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. package ru.itschool;
  2.  
  3. import java.util.Comparator;
  4.  
  5. public class Student{
  6.     private String name;
  7.     private int num;
  8.  
  9.     public Student(String name, int num){
  10.         this.name = name;
  11.         this.num = num;
  12.     }
  13.  
  14.     @Override
  15.     public String toString() {
  16.         return "Student{" +
  17.                 "name='" + name + '\'' +
  18.                 ", num=" + num +
  19.                 '}';
  20.     }
  21.  
  22.     public int getNum() {
  23.         return num;
  24.     }
  25.  
  26.     public String getName() {
  27.         return name;
  28.     }
  29.  
  30.     static class StudentCompare implements Comparator<Student> {
  31.  
  32.         @Override
  33.         public int compare(Student o1, Student o2) {
  34.             if(o1.getNum() > o2.getNum())
  35.                 return 1;
  36.             else if(o1.getNum() < o2.getNum())
  37.                 return -1;
  38.             return o1.getName().compareTo(o2.getName());
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement