【案例4-8】模拟物流快递系统程序设计

案例描述

网购已成为人们生活的重要组成部分,当人们在购物网站中下订单后,订单中的货物就会在经过一系列的流程后,送到客户的手中。而在送货期间,物流管理人员可以在系统中查看所有物品的物流信息。编写一个模拟物流快递系统的程序,模拟后台系统处理货物的过程。

创建Careable接口

package 物流快递;
//定义交通工具保养接口
public interface Careable {
    public abstract void upKeep();
}




创建GPS接口

package 物流快递;
//定义GPS接口,具备GPS定位功能
public interface GPS {
    public String showCoordinate();
}

定义一个手机类

package 物流快递;
//定义一个手机类,实现GPS接口,具有定位功能
class Phone implements GPS{
    public Phone() {
        super();
    }
    public String showCoordinate() {
        String location = "193,485";
        return location;
    }
}

定义快递任务类

package 物流快递;
//快递任务类
class SendTask {
    private String number;//快递单号
    private double goodsWeight;
    public SendTask() {
        super();
    }
    public SendTask(String number,double goodWeight){
        this.number = number;
        this.goodsWeight = goodWeight;
    }
    public void sendBefore() {
        System.out.println("订单开始处理,仓库验货中。。。");
        System.out.println("货物重量:"+this.getGoodsWeight()+"kg");
        System.out.println("货物检验完毕");
        System.out.println("货物填装完毕");
        System.out.println("运货人已通知");
        System.out.println("快递单号:"+this.getNumber());
    }
    public void send(Transportation t,GPS tool) {
        System.out.println("运货人"+t.getAdmin()+"正在驾驶编号为"+t.getNumber()+"的"+t.getModel()+"发送货物");
        t.transport();
        String showCoordinate = tool.showCoordinate();
        System.out.println("货物当前的坐标为:"+showCoordinate);
    }
    public void sendAfter(Transportation t) {
        System.out.println("货物运输任务已完成");
        System.out.println("运货人"+t.getAdmin()+"所驾驶的编号为"+t.getNumber()+"的"+t.getModel()+"已归还!");
    }
    public String getNumber() {
        return number;
    }
    public void setNumber(String number) {
        this.number = number;
    }
    public double getGoodsWeight() {
        return goodsWeight;
    }
    public void setGoodsWeight(double goodsWeight) {
        this.goodsWeight = goodsWeight;
    }
}





定义运输类

package 物流快递;

public abstract class Transportation {
    private String number; //编号
    private String model;//型号
    private String admin; //货运负责人
    public Transportation() {
        super();
    }
    public Transportation(String number, String model,String admin) {
        this.number = number;
        this.model = model;
        this.admin = admin;
    }
    public abstract void transport();
    public void setNumber(String number) {
        this.number= number;
    }
    public String getNumber() {
        return number;
    }
    public void setModel(String model) {
        this.model = model;
    }
    public String getModel() {
        return model;
    }
    public void setAdmin(String admin) {
        this.admin = admin;
    }
    public String getAdmin() {
        return admin;
    }

}

定义专属运输车类

package 物流快递;
//专属运输车类
public class ZTransportation extends Transportation implements Careable{
     public ZTransportation() {
         super();
     }
     public ZTransportation(String number,String model,String admin) {
         super(number,model,admin);
     }
     public void transport() {
         System.out.println("运输中");
     }
     public void upKeep() {
         System.out.println("货物运输车辆保养完毕");
     }
}



定义测试类

package 物流快递;
public class test {
    public static void main(String[] args) {
        //快递任务对象
        SendTask task = new SendTask("HYX600235",76.34);
        //调用送前准备方法
        task.sendBefore();
        System.out.println("=================================");
        //创建交通工具
        ZTransportation t = new ZTransportation("Z025","大奔","小韩");
        //创建GPS对象
        Phone p = new Phone();
        //将交通工具与GPS工具传入送货方法
        task.send(t, p);
        System.out.println("=================================");
        //调用送后操作方法
        task.sendAfter(t);
        t.upKeep();
    }
}

  • 1
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值