java汽车租赁系统

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

packageRentCar;publicclassBusextendsMotoVehicle{privateintseatCount;//构造方法publicBus(){}publicBus(Stringno,Stringbrand,intseatCount){super(no,brand);this.seatCount=seatCount;}//获取座位数publicintgetSeat(){returnseatCount;}//计算租金publicintcalRent(intdays){intrent=0;if(seatCount=16){rent=800*days;}else{rent=1500*days;}returnrent;}}……………………………………………………………………………………………………………packageRentCar;publicclassCarextendsMotoVehicle{privateStringtype;//轿车的型号//构造方法publicCar(){}publicCar(Stringno,Stringbrand,Stringtype){super(no,brand);this.type=type;}//设置轿车的型号publicvoidsetType(Stringtype){this.type=type;}//返回轿车型号publicStringgetType(){returntype;}//实现父类抽象方法,计算租金publicintcalRent(intdays){intrent=0;if(宝马.equals(getBrand())){rent=days*500;}elseif(丰田.equals(getBrand())){if(type.equals(GL8)){rent=days*600;}else{rent=days*300;}}returnrent;}}……………………………………………………………………………………………………………packageRentCar;publicclassCustomer{privateStringname;publicCustomer(){}publicCustomer(Stringname){this.name=name;}publicStringgetName(){returnname;}publicintcalcTotalRent(MotoVehicle[]moto,intdays){intrent=0;for(inti=0;imoto.length;i++){if(moto[i]!=null){rent=rent+moto[i].calRent(days);}}returnrent;}}……………………………………………………………………………………………………………packageRentCar;publicabstractclassMotoVehicle{privateStringno;//车牌号privateStringbrand;//品牌//构造方法publicMotoVehicle(){}publicMotoVehicle(Stringno,Stringbrand){this.no=no;this.brand=brand;}//返回机动车辆的牌照publicStringgetNo(){returnno;}//返回机动车辆的品牌publicStringgetBrand(){returnbrand;}//计算租金的抽象方法publicabstractintcalRent(intdays);}……………………………………………………………………………………………………………packageRentCar;importjava.util.Scanner;publicclassTest{publicstaticvoidmain(String[]args){Scannerinput=newScanner(System.in);intdays=0;//租赁的天数intmotoType;//汽车大类型Stringbrand;//汽车品牌Stringtype=null;//汽车具体类型intseat;//座位数Stringno;//拍照Stringanswer;//是否继续MotoVehicle[]moto=newMotoVehicle[10];Customercustomer=newCustomer(小明);System.out.println(欢迎来到汽车租赁公司!);System.out.print(请输入要租赁的天数:);days=input.nextInt();do{System.out.print(请输入要租赁的汽车类型(1.轿车2.客车):);motoType=input.nextInt();intrandom=(int)(Math.random()*(99999-10000)+10000);switch(motoType){case1:no=粤A+random;//车辆牌照System.out.print(请输入要租赁的汽车品牌(1.宝马2.丰田):);if(input.nextInt()==1){brand=宝马;type=320i;}else{brand=丰田;type=RAV4;}//实例化一个轿车对象,并添加到moto数组中for(inti=0;imoto.length;i++){if(moto[i]==null){moto[i]=newCar(no,brand,type);break;}}break;case2:no=粤A+random;System.out.print(请输入要租赁的汽车品牌(1.黄海2.金龙):);//根据选择得到汽车品牌if(input.nextInt()==1){brand=黄海;}else{brand=金龙;}System.out.print(请输入客车的座位数:);seat=input.nextInt();//汽车座位数//实例化一个轿车对象,并添加到moto数组中for(inti=0;imoto.length;i++){if(moto[i]==null){moto[i]=newBus(no,brand,seat);//实例化一个汽车对象break;}}break;}System.out.print(是否继续租车?(y/n):);answer=input.next();}while(answer.equals(y));System.out.println(汽车牌号\t汽车品牌);for(inti=0;imoto.length;i++){if(moto[i]!=null){if(moto[i]instanceofCar){Carc=(Car)moto[i];System.out.println(c.getNo()+\t+c.getBrand());}else{Busb=(Bus)moto[i];System.out.println(b.getNo()+\t+b.getBrand());}}}System.out.println(客户名:+customer.getName()+,租赁天数:+days+,总费用:+customer.calcTotalRent(moto,days));}}……………………………………………………………………………………………………………packageRentCar;publicclassTruckextendsMotoVehicle{privateintweight;//吨位publicTruck(){}publicTruck(Stringno,Stringbrand,intweight){super(no,brand);this.weight=weight;}publicintgetWeight(){returnweight;}publicintcalRent(intdays){intrent=0;rent=weight*50*days;returnrent;}}

1 / 7
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功