Advertisement
thieumao

Sap xep

Aug 27th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1.     private static void xuatDanhSachGiangVienDaSapXep(ArrayList<GiangVien> dsGiangVien) {
  2.         Collections.sort(dsGiangVien, new Comparator<GiangVien>() {
  3.             @Override
  4.             public int compare(GiangVien gv1, GiangVien gv2) {
  5.                 if (gv1.getHoTen().compareTo(gv2.getHoTen()) > 0) {
  6.                     return 1;
  7.                 } else {
  8.                     if (gv1.getHoTen().compareTo(gv2.getHoTen()) == 0) {
  9.                         if (gv1.getLuong() < gv2.getLuong()) {
  10.                             return 1;
  11.                         } else if (gv1.getLuong() > gv2.getLuong()) {
  12.                             return -1;
  13.                         }
  14.                         return 0;
  15.                     } else {
  16.                         return -1;
  17.                     }
  18.                 }
  19.             }
  20.         });
  21.         for (int i = 0; i < dsGiangVien.size(); i++) {
  22.             System.out.println(">> Giang vien thu " + (i+1));
  23.             GiangVien giangVien = dsGiangVien.get(i);
  24.             giangVien.xuat();
  25.         }
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement