Java如何实现汽车租赁系统(java,开发技术)

时间:2024-04-28 10:02:33 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

汽车租赁:

分为客车和轿车两种:

客车小于20座:500一天,大于20座:900一天。

轿车分为豪华和普通:豪华600一天,普通200一天。

效果图:

Java如何实现汽车租赁系统

Java如何实现汽车租赁系统

代码如下:

机动车类:

packagebusTest;/*机动车类*/publicabstractclassMotoVehicle{privateStringcarNumber;//车牌号privateStringcarBrand;//车品牌//构造方法publicMotoVehicle(){}publicMotoVehicle(StringcarNumber,StringcarBrand){this.carNumber=carNumber;this.carBrand=carBrand;}//get/setpublicStringgetCarNumber(){returncarNumber;}publicvoidsetCarNumber(StringcarNumber){this.carNumber=carNumber;}publicStringgetCarBrand(){returncarBrand;}publicvoidsetCarBrand(StringcarBrand){this.carNumber=carNumber;}/*计算租赁的方法*/publicabstractintcalRent(intdays);}

客车类:

packagebusTest;publicclassBusextendsMotoVehicle{privateintsetCount;//座位数//通过构造方法初始化对象publicBus(StringcarNUmber,Stringbrand,intsetCount){super(carNUmber,brand);this.setCount=setCount;}@OverridepublicintcalRent(intdays){//根据座位数量来判断租赁的金额if(this.setCount<20){returndays*500;}else{returndays*900;}}publicvoidshowBusInfo(intdays){System.out.println("*");System.out.println("\t车牌号:"+super.getCarNumber());System.out.println("\t车品牌:"+super.getCarBrand());System.out.println("\t座位数:"+this.setCount);System.out.println("\t租赁天数:"+days);System.out.println("\t金额:"+calRent(days));}}

轿车类:

packagebusTest;publicclassCarextendsMotoVehicle{privateStringtype;//汽车类型普通/豪华//通过构造方法初始化对象publicCar(StringcarNUmber,Stringbrand,Stringtype){super(carNUmber,brand);this.type=type;}@OverridepublicintcalRent(intdays){//根据类型来决定价格if("豪车".equals(type)){returndays*600;}else{returndays*200;}}publicvoidshowCarInfo(intdays){System.out.println("*");System.out.println("\t车牌号:"+super.getCarNumber());System.out.println("\t车品牌:"+super.getCarBrand());System.out.println("\t车类型:"+this.type);System.out.println("\t租赁天数:"+days);System.out.println("\t金额:"+calRent(days));}}

租车顾客类:

packagebusTest;/*顾客类*/importjava.util.Scanner;publicclassCustomer{privateStringname;privateintsum=0;//当不确定我的购物车内具体是轿车还是客车,那就以父亲类类型创建对象数组MotoVehicle[]motos=newMotoVehicle[10];Scannerinput=newScanner(System.in);publicvoidshowMenu(){//定义一个父类机动车的对象,在下面可以接收MotoVehiclemoto=null;System.out.println("******汽车租赁系统*******");Stringanswer;do{System.out.println("1、租赁客车2、租赁轿车");System.out.print("请输入编号:");intnum=input.nextInt();if(num==1){//创建租赁的客车对象moto=rentBus();}elseif(num==2){//创建租赁的轿车对象moto=rentCar();}for(inti=0;i<motos.length;i++){if(motos[i]==null){motos[i]=moto;break;}}System.out.print("是否继续租赁?:y/n");answer=input.next();}while(!"n".equals(answer));System.out.print("请输入你的姓名:");this.name=input.next();System.out.print("租赁的天数:");intdays=input.nextInt();//根据天数来统计租赁金额calTotalRent(days);//显示租赁的信息showInfo(days);}privatevoidshowInfo(intdays){System.out.println("---------------------租赁汽车信息---------------------");for(inti=0;i<motos.length;i++){MotoVehiclemoto=this.motos[i];if(moto!=null){if(motoinstanceofBus){Busbus=(Bus)moto;bus.showBusInfo(days);}elseif(motoinstanceofCar){Carcar=(Car)moto;car.showCarInfo(days);}}}System.out.println("\t顾客:"+this.name+"\t\t总金额:"+sum);System.out.println("----------------------------------------------------");}privatevoidcalTotalRent(intdays){inttotal=0;for(MotoVehiclemoto:motos){if(moto!=null){intrent=moto.calRent(days);total+=rent;//累加总金额}this.sum=total;//把总金额复制给全局变量sum}}//轿车privateMotoVehiclerentCar(){System.out.print("请输入轿车品牌:");Stringbrand=input.next();System.out.print("请输入轿车车牌号:");StringcarNumber=input.next();System.out.print("请选择轿车类型[1、豪车2、普通车:]");intchoise=input.nextInt();Stringtype;if(choise==1){type="豪车";}else{type="普通型";}returnnewCar(carNumber,brand,type);}//客车privateMotoVehiclerentBus(){System.out.print("请输入客车品牌:");Stringbrand=input.next();System.out.print("请输入客车车牌号:");StringcarNumber=input.next();System.out.print("请输入客车座位数:");intseatCount=input.nextInt();returnnewBus(carNumber,brand,seatCount);}}

测试类:

packagebusTest;publicclassTestMain{publicstaticvoidmain(String[]args){Customercustomer=newCustomer();customer.showMenu();}}
 </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:Java如何实现汽车租赁系统的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:Java中String类有哪些使用方法下一篇:

11 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18