java汽车租赁系统(共7页)_第1页
java汽车租赁系统(共7页)_第2页
java汽车租赁系统(共7页)_第3页
java汽车租赁系统(共7页)_第4页
java汽车租赁系统(共7页)_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

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

文档简介

1、package RentCar;public class Bus extends MotoVehicleprivate int seatCount;/构造方法public Bus()public Bus(String no, String brand, int seatCount)super(no,brand);this.seatCount = seatCount;/获取座位数public int getSeat()return seatCount;/计算租金public int calRent(int days)int rent = 0; if(seatCount = 16)rent = 8

2、00 * days;elserent = 1500 * days;return rent;package RentCar;public class Car extends MotoVehicle private String type; / 轿车的型号/构造方法public Car()public Car(String no, String brand, String type)super(no,brand);this.type = type;/设置轿车的型号public void setType(String type)this.type = type;/返回轿车型号public Strin

3、g getType()return type;/实现父类抽象方法,计算租金public int calRent(int days)int rent = 0;if(宝马.equals(getBrand()rent = days * 500;else if(丰田.equals(getBrand()if(type.equals(GL8)rent = days * 600;elserent = days * 300;return rent;package RentCar;public class Customer private String name;public Customer()public

4、Customer(String name) = name;public String getName()return name;public int calcTotalRent(MotoVehicle moto, int days)int rent = 0 ;for(int i = 0 ;i moto.length; i+)if(motoi!=null)rent = rent + motoi.calRent(days);return rent;package RentCar;public abstract class MotoVehicle private String no

5、; /车牌号private String brand; /品牌/构造方法public MotoVehicle()public MotoVehicle(String no, String brand)this.no = no;this.brand = brand;/返回机动车辆的牌照public String getNo()return no;/返回机动车辆的品牌public String getBrand()return brand;/计算租金的抽象方法public abstract int calRent(int days);package RentCar;import java.util.

6、Scanner;public class Test public static void main(String args)Scanner input = new Scanner(System.in);int days = 0; /租赁的天数int motoType ; /汽车大类型String brand ; /汽车品牌String type = null; /汽车具体类型int seat; /座位数String no; /拍照String answer; /是否继续MotoVehicle moto = new MotoVehicle10;Customer customer = new Cu

7、stomer(小明);System.out.println(欢迎来到汽车租赁公司!);System.out.print(请输入要租赁的天数:);days = input.nextInt();doSystem.out.print(请输入要租赁的汽车类型(1.轿车 2.客车):);motoType = input.nextInt();int random = (int)(Math.random()*(99999-10000)+10000);switch(motoType)case 1:no = 粤A + random; /车辆牌照System.out.print(请输入要租赁的汽车品牌(1.宝马

8、2.丰田):);if(input.nextInt() = 1)brand = 宝马;type = 320i;elsebrand = 丰田;type = RAV4;/实例化一个轿车对象,并添加到moto数组中for(int i = 0 ; i moto.length ;i +)if(motoi = null)motoi = new Car(no,brand,type);break;break;case 2:no = 粤A + random; System.out.print(请输入要租赁的汽车品牌(1.黄海 2.金龙):);/根据选择得到汽车品牌if(input.nextInt() =1)bra

9、nd = 黄海;elsebrand = 金龙;System.out.print(请输入客车的座位数:);seat = input.nextInt(); /汽车座位数/实例化一个轿车对象,并添加到moto数组中for(int i = 0 ; i moto.length ;i +)if(motoi = null)motoi = new Bus(no,brand,seat); /实例化一个汽车对象break;break;System.out.print(是否继续租车?(y/n):);answer = input.next();while(answer.equals(y);System.out.pri

10、ntln(汽车牌号t汽车品牌);for(int i = 0 ; i moto.length ;i +)if(motoi != null)if(motoi instanceof Car)Car c = (Car)motoi;System.out.println(c.getNo()+t+c.getBrand();elseBus b = (Bus)motoi;System.out.println(b.getNo()+t+b.getBrand();System.out.println(客户名:+customer.getName()+,租赁天数:+days+,总费用:+customer.calcTotalRent(moto, days);package RentCar;public class Truck extends MotoVehicle private int weight; /吨位public Truck()public Truck(String no, String brand

温馨提示

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

评论

0/150

提交评论