package com.sf._03_linked_list.demo2;

import java.util.LinkedList;

public class ExpressSortStack {
    public static LinkedList<Express> expresses = new LinkedList<>();


    /**
     * 把快递放到分拣栈顶部
     * 把expres 放到linkedList
     */
    public static void pushExpress(Express express){
        expresses.push(express);
        System.out.println("已经放进待分拣区域"+ express);
    }

    /**
     * 分拣员从栈顶去除快递 标记已分拣
     */
    public static void popExpress(){
        /**
         * 判断集合size 是否大于0
         */
        if(expresses.size() == 0){
            System.out.println("已经没有快递了");
            return;
        }
        Express express = expresses.pop();
        System.out.println("快递已分拣"+ express +"已经投放到"+ express.getAddress()+"区域");
    }

    /**
     * 查看下次要分拣快递信息
     * 查看栈顶信息 peek
     */
    public static void peekExpress(){
        // 判断区域是否有快递
        if(expresses.size() == 0){
            System.out.println("已经没有快递了");
            return;
        }
        // 查看一下栈顶信息  就是他下一次要分拣的快递
        Express express = expresses.peek();
        System.out.println("下一次要分拣快递信息为:"+express);
    }

    /**
     * 查看栈里面快递总重量
     */
    public static void  statWeight(){
        if(expresses.size() == 0){
            System.out.println("已经没有快递了");
            return;
        }
        double totalWeight = 0;
        int overWeightCount = 0;

        for (Express express : expresses) {
            // 拿每一个快递重量累加
            totalWeight += express.getWeight();
            if(express.getWeight()>5){
                overWeightCount++;
            }
        }
        System.out.println("总重量为:"+ totalWeight);
        System.out.println("超重快递:"+ overWeightCount);
        System.out.println("快递总数量"+ expresses.size());
    }

    public static void main(String[] args) {
        pushExpress(new Express("001","广州",1));
        pushExpress(new Express("002","北京",6));
        pushExpress(new Express("003","上海",10));
//        System.out.println(expresses);

//        popExpress();
//
//        peekExpress();
        statWeight();
    }

}
