java模拟物流快递系统程序word.doc

java模拟物流快递系统程序word.doc
java模拟物流快递系统程序word.doc

贺州学院

实验报告

班级16物联2班学号1610818044 姓名黄涛评分等级

实验名称模拟物流快递系统程序设计日期2017-10-25

一、实验要求

1、输入、编辑、调试和运行例4.1;

2、输入工具类;

要求输出结果如下所示:

3、从键盘中输入基本信息将它们输出。

要求输出结果如下所示:(数值任意)

4、输入、编辑、调试和运行例4.4;

二、实验目的

1、学会分析“模拟物流快递系统程序设计”程序任务实现的逻辑思路。

2、能够独立完成“模拟物流快递系统程序设计”程序的源代码编写。编译及运行。

3、理解类和对象的封装,继承以及多态的概念和使用。三、实验环境:Eclipse软件编译环境

四、

实验设计过程:

(1)将交通工具定义成一个抽象类,和一个抽象的运输方法

(2)定义保养接口,具备交通工具的保养接口

(3)定义一个专用运输车类

(4)定义一个快递任务类

(5)定义一个包含gps接口,和实现了该接口的仪器类

五、实验代码

package cn.itcast.chapter04.task02;

/*

* 交通工具类

*/

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;

}

}

/*

* 定义保养接口,具备保养功能。

*/

public interface Careable {

//保养方法

public abstract void upKeep();

}

/*

* 专用运输车类

*/

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("货物运输车辆保养完毕!");

}

}

/*

* 快递任务类

*/

public class SendTask {

private String number; // 快递单号

private double goodsWeight; // 货物重量

public SendTask() {

super(); //可省略

}

public SendTask(String number, double goodsWeight) {

this.number = number;

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. 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;

}

}

/*

* 定义GPS接口,具备GPS定位功能。

*/

public interface GPS{

//显示坐标的方法

public String showCoordinate();

}

/*

* 随意定义一个物品,实现GPS接口,拥有定位功能。

*/

class Phone implements GPS{

public Phone() { //空参构造

super();

}

//定位方法

public String showCoordinate() {

String location = "193,485";

return location;

}

}/*

* 定义测试类

*/

public class Task02Test {

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();

}

}

六、运行结果

相关主题
相关文档
最新文档