网购已成为人们生活的重要组成部分,当人们在购物网站中下订单后,订单中的货物就会在经过一系列的流程后,送到客户的手中。而在送货期间,物流管理人员可以在系统中查看所有物品的物流信息。编写一个模拟物流快递系统的程序,模拟后台系统处理货物的过程。
此案例分为两个接口 Careable GPS和五个类 Phone SendTask Test Transportation ZTransprotation
Careable接口
public interface Careable {
public abstract void upKeep();
}
GPS接口
public interface GPS {
public abstract String showGPS();
}
Phone 类
public class Phone implements GPS {
@Override
public String showGPS() {
return "196,489";
}
}
SendTask类
//快递任务类
public class SendTask {
private String number;
private double goodsWeight;
public SendTask(String number, double goodsWeight) {
this.number = number;
this.goodsWeight = goodsWeight;
}
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;
}
//发送前
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.transportation();
System.out.println("货车当前坐标"+tool.showGPS());
}
//发送后
public void send(Transportation t){
System.out.println("货物运输任务完成");
System.out.println("运货人"+t.getAdmin()+"所驾驶的编号为;"+t.getNumber()+"的"+t.getModel()+"已归还");
}
public void SendAfter(ZTransportation t) {
}
}
Transportation 类
//运输工具类
public abstract class Transportation {
private String number;//编号
private String model;//型号
private String admin;//负责人
public Transportation(String number, String model, String admin) {
this.number = number;
this.model = model;
this.admin = admin;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getAdmin() {
return admin;
}
public void setAdmin(String admin) {
this.admin = admin;
}
public abstract void transportation();
}
ZTransprotation类
public class ZTransportation extends Transportation implements Careable{
public ZTransportation(String number, String model, String admin) {
super(number, model, admin);
}
@Override
public void upKeep() {
System.out.println("运输完成,保养车辆。。。");
}
@Override
public void transportation() {
System.out.println("运输进行中。。。");
}
}
Test类
public class Test {
public static void main(String[] args) {
SendTask task =new SendTask("TB1001",10);
task.sendBefore();
System.out.println("==========================");
ZTransportation t =new ZTransportation("Z001","大奔","小韩");
Phone p =new Phone();
task.send(t,p);
System.out.println("=======================");
task.SendAfter(t);
t.upKeep();
}
}
结果展示