Manager

 avatar
unknown
plain_text
2 years ago
2.0 kB
4
Indexable
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package s00017;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

/**
 * Lab07 SE1606
 *
 * @author Ngo Hai Bang CE160624
 */
public class Manager {

    ArrayList<Person> PersonList;

    /**
     * Constructor
     *
     */
    public Manager() {
        this.PersonList = new ArrayList<Person>();
    }

    /**
     * Nhập dữ liệu cho 3 đối tượng
     *
     */
    public void input() {
        System.out.println("=====Management Person programer=====");
        //tạo 3 đối tượng và lưu vào arraylist
        for (int i = 0; i < 3; ++i) {
            Person p1 = new Person();
            p1.inputPersonInfo();
            this.PersonList.add(p1);
            System.out.println("");
        }
    }

    /**
     * Sắp xếp theo thứ tự luongq tăng dần
     *
     */
    public void sortBySalary() {
        Collections.sort(PersonList, new Comparator<Person>() {
            @Override
            public int compare(Person ps1, Person ps2) {    //so sánh và sắp xếp
                if (ps1.getSalary() < ps2.getSalary()) {
                    return -1;
                } else {
                    if (ps1.getSalary() == ps2.getSalary()) {
                        return 0;
                    } else {
                        return 1;
                    }
                }
            }
        });
    }
    
    /**
     * Hiển thị tất cả thông tin của đối tượng
     *
     */
    public void disPlay() {
        System.out.println("");
        for (int i = 0; i < 3; ++i) {   //lượt qua từng phần tử và hiển thị ra màn hình
            Person person = this.PersonList.get(i);
            person.outputPersonInfo();
        }
    }

}
Editor is loading...