AkhmadGhafirin
5/4/2017 - 1:39 PM

Main Mahasiswa

package comparableAndComparator.mahasiswa;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by ahmad on 04/05/17.
 */
public class MainMahasiswa {
    public static void main(String[] args) {
        List<Mahasiswa> mahasiswaList = new ArrayList<>();
        mahasiswaList.add(new Mahasiswa(5, "Budi ", 1.12));
        mahasiswaList.add(new Mahasiswa(2, "Ahmad",2.32));
        mahasiswaList.add(new Mahasiswa(4, "Alvin",1.45));
        mahasiswaList.add(new Mahasiswa(1, "Dani ", 3.22));
        mahasiswaList.add(new Mahasiswa(6, "Aldi ", 2.25));
        mahasiswaList.add(new Mahasiswa(3, "Ibnu ", 3.25));

        System.out.println("Berdasarkan Nama");
        Collections.sort(mahasiswaList);
        for (Mahasiswa mahasiswa : mahasiswaList) {
            System.out.println(mahasiswa.toString());
        }
        System.out.println("\nBerdasarkan Nrp");
        Collections.sort(mahasiswaList, new ComparatorNrp());
        for (Mahasiswa mahasiswa : mahasiswaList) {
            System.out.println(mahasiswa.toString());
        }
        System.out.println("\nBerdasarkan Ipk");
        Collections.sort(mahasiswaList, new ComparatorIpk());
        for (Mahasiswa mahasiswa : mahasiswaList) {
            System.out.println(mahasiswa.toString());
        }
    }
}