Manager

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.9 kB
3
Indexable
Never
/*
 * 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 vo7;

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

/**
 *
 * @author HP
 */
public class Manager {

    ArrayList<Person> PersonList;

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

    /**
     * Input data for 3 objects
     *
     */
    public void create() {
        System.out.println("=====Management Person programer=====");
        //create 3 objects and save to arraylist
        for (int i = 0; i < 3; ++i) {
            Person p1 = new Person();
            p1.inputPersonInfo();
            this.PersonList.add(p1);
            System.out.println("");
        }
    }

    /**
     * Sort by ascending salary
     *
     */
    public void sortBySalary() {
        Collections.sort(PersonList, new Comparator<Person>() {
            @Override
            public int compare(Person ps1, Person ps2) {    //compare and sort
                if (ps1.getSalary() < ps2.getSalary()) {
                    return -1;
                } else {
                    if (ps1.getSalary() == ps2.getSalary()) {
                        return 0;
                    } else {
                        return 1;
                    }
                }
            }
        });
    }

    /**
     * Show all information of the object
     *
     */
    public void display() {
        System.out.println("");
        for (int i = 0; i < 3; ++i) {   //run through each element and display it on the screen
            Person person = this.PersonList.get(i);
            person.outputPersonInfo();
        }
    }

}