Java程序设计项目化教程-5.4项目实训脚本_第1页
Java程序设计项目化教程-5.4项目实训脚本_第2页
Java程序设计项目化教程-5.4项目实训脚本_第3页
Java程序设计项目化教程-5.4项目实训脚本_第4页
Java程序设计项目化教程-5.4项目实训脚本_第5页
已阅读5页,还剩14页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

01020304Java语言基础基本数据类型运算符Scanner类C目录ONTENTS05项目实训运用面向对象知识结合本项目介绍的内容,设计一个模拟货物快递系统程序。5.4.1实训任务能显示订单信息包括货物状态、订单号、运货人。显示运输车辆的位置信息。显示货物运输完成信息以及车辆状态信息。5.4.1实训任务PART5.4.2任务实施5.4.2任务实施1.定义交通工具类包含属性有:车辆编号,车辆型号以及运货人属性,还需要定义一个抽象的运输方法。packagechapter5;publicabstractclassStransportation{//交通工具类

privateStringtruckid;//车辆编号

privateStringmodel; //车辆型号

privateStringdriver; //运货人

publicStransportation(){ super();}5.4.2任务实施publicStransportation(Stringtruckid,Stringmodel,Stringdriver){ this.truckid=truckid; this.model=model; this.driver=driver;}publicabstractvoidtransport();//运输方法publicvoidsetTruckid(Stringtruckid){//设置车辆编号

this.truckid=truckid;} publicStringgetTruckid(){5.4.2任务实施publicvoidsetModel(Stringmodel){//设置车辆型号

this.model=model;} publicStringgetModel(){ returnmodel;} publicvoidsetDriver(Stringdriver)//设置运货人

this.driver=driver; } publicStringgetDriver(){ returndriver; }}privatedoubleprice;//价格

privateintstore;//库存publicBook(intid,Stringname,doubleprice,intstore){//有参构造方法

this.id=id;=name;this.price=price;this.store=store;}publicintgetid(){//获取书号方法

returnid;}publicStringgetname(){//获取书名方法

returnname;}publicdoublegetprice(){//获取价格方法

returnprice;}publicintgetstore(){//获取库存方法

returnstore;}}5.4.2任务实施2.定义交通工具维修接口Repair,该接口中包含车辆维修的方法5.4.2任务实施packagechapter5;publicinterfaceRepair{//定义维修接口publicabstractvoidupKeep();//维修方法}5.4.2任务实施3.定义运输车类Zstransportation,该类继承了交通工具类,并实现了维修接口,其实现代码如下所示。5.4.2任务实施packagechapter5;publicclassZstransportationextendsStransportationimplementsRepair{publicZstransportation(){//无参构造方法

super();}//有参构造:车辆编号、型号、运货人publicZstransportation(Stringtruckid,Stringmodel,Stringdriver){super(truckid,model,driver);}publicvoidtransport()//运输方法

{System.out.println("货物运输进行中。。。");}publicvoidupKeep()//重写车辆维修方法

{System.out.println("货物运输车辆维修完毕!");}}5.4.2任务实施4.定义快递任务类TransTaskpackagechapter5;publicclassTransTask{ privateStringnumber;//快递单号

privatedoublegoodsWeight;//货物重量

publicTransTask(){ super();//可省略

} publicTransTask(Stringnumber,doublegoodsWeight){ this.number=number; this.goodsWeight=goodsWeight;}5.4.2任务实施publicvoidtransBefore(){//送货前准备操作

System.out.println("订单开始处理,仓库验货中。。。"); System.out.println("货物重量:

"+this.getGoodsWeight()+"kg"); System.out.println("货物检验完毕!"); System.out.println("货物装载完毕!"); System.out.println("运货人已通知!"); System.out.println("快递单号:"+this.getNumber()); } publicvoidtrans(Zstransportationt,BDStool){//发送货物操作 System.out.println("运货人"+t.getDriver()+"正在驾驶车辆编号为"+t.getTruckid()+"的"+t.getModel()+"发送货物!");5.4.2任务实施

t.transport(); StringshowCoordinate=tool.showCoordinate(); System.out.println("货物当前所在的坐标为:"+showCoordinate);} publicvoidtransAfter(Zstransportationt){//货物送到后操作

System.out.println("货物运输任务已完成!"); System.out.println("运货人"+t.getDriver()+"所驾驶的车辆编号为"+t.getTruckid()+"的5.4.2任务实施

5.定义包含显示位置功能的BDS接口和实现类Phonepackagechapter5;publicinterfaceBDS{publicStringshowCoordinate();}//显示坐标的方法

packagechapter5;classPhoneimplementsBDS{ publicPhone(){super();}//空参构造方法

publicStringshowCoordinate(){//定位方法

Stringlocation="111,444"; returnlocation; }}5.4.2任务实施

6.定义测试类,调用不同的构造方法创建不同对象并设置初值,测试程序运行结果

packagechapter5;publicclassTaskTest{ publicstaticvoidmain(String[]args){ TransTasktask1=newTransTask("YT931236",77);//快递任务类对象

task1.transBefore();//调用送货前准备方法

System.out.println("======================");//创建交通工具对象

Zstransportationtr=newZstransportation("B036","卡车","张三");Phoneph=newPhone();//创建GPS工具对象

task1.trans(tr,ph);//将交通工具与GPS工具传入送货方法

System.out.p

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论