Java如何实现汽车租赁系统
发表于:2025-11-07 作者:千家信息网编辑
千家信息网最后更新 2025年11月07日,这篇文章主要为大家展示了"Java如何实现汽车租赁系统",内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下"Java如何实现汽车租赁系统"这篇文章吧。汽车租赁:分
千家信息网最后更新 2025年11月07日Java如何实现汽车租赁系统
这篇文章主要为大家展示了"Java如何实现汽车租赁系统",内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下"Java如何实现汽车租赁系统"这篇文章吧。
汽车租赁:
分为客车和轿车两种:
客车小于20座:500一天,大于20座:900一天。
轿车分为豪华和普通:豪华600一天,普通200一天。
效果图:


代码如下:
机动车类:
package busTest;/*机动车类 */public abstract class MotoVehicle { private String carNumber; //车牌号 private String carBrand; // 车品牌 //构造方法 public MotoVehicle(){} public MotoVehicle(String carNumber, String carBrand) { this.carNumber = carNumber; this.carBrand = carBrand; } // get/set public String getCarNumber(){ return carNumber; } public void setCarNumber(String carNumber){ this.carNumber = carNumber; } public String getCarBrand(){ return carBrand; } public void setCarBrand(String carBrand){ this.carNumber = carNumber; } /* 计算租赁的方法 */ public abstract int calRent(int days);}客车类:
package busTest;public class Bus extends MotoVehicle { private int setCount; //座位数 //通过构造方法初始化对象 public Bus(String carNUmber, String brand, int setCount) { super(carNUmber, brand); this.setCount = setCount; } @Override public int calRent(int days) { //根据座位数量来判断租赁的金额 if (this.setCount < 20) { return days * 500; } else { return days * 900; } } public void showBusInfo(int days) { 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)); }}轿车类:
package busTest;public class Car extends MotoVehicle { private String type; //汽车类型 普通/豪华 //通过构造方法初始化对象 public Car(String carNUmber, String brand, String type) { super(carNUmber, brand); this.type = type; } @Override public int calRent(int days) { //根据类型来决定价格 if ("豪车".equals(type)) { return days * 600; } else { return days * 200; } } public void showCarInfo(int days) { 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)); }}租车顾客类:
package busTest;/*顾客类 */import java.util.Scanner;public class Customer { private String name; private int sum = 0; //当不确定我的购物车内具体是轿车还是客车,那就以父亲类类型创建对象数组 MotoVehicle[] motos = new MotoVehicle[10]; Scanner input = new Scanner(System.in); public void showMenu() { //定义一个父类机动车的对象,在下面可以接收 MotoVehicle moto = null; System.out.println("******汽车租赁系统*******"); String answer; do { System.out.println("1、租赁客车 2、租赁轿车"); System.out.print("请输入编号:"); int num = input.nextInt(); if (num == 1) { //创建租赁的客车对象 moto = rentBus(); } else if (num == 2) { //创建租赁的轿车对象 moto = rentCar(); } for (int i = 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("租赁的天数:"); int days = input.nextInt(); //根据天数来统计租赁金额 calTotalRent(days); //显示租赁的信息 showInfo(days); } private void showInfo(int days) { System.out.println("---------------------租赁汽车信息---------------------"); for (int i = 0; i < motos.length; i++) { MotoVehicle moto = this.motos[i]; if (moto != null) { if (moto instanceof Bus) { Bus bus = (Bus) moto; bus.showBusInfo(days); } else if (moto instanceof Car) { Car car = (Car) moto; car.showCarInfo(days); } } } System.out.println("\t顾客:" + this.name + "\t\t总金额:" + sum); System.out.println("----------------------------------------------------"); } private void calTotalRent(int days) { int total = 0; for (MotoVehicle moto : motos) { if (moto != null) { int rent = moto.calRent(days); total += rent; //累加总金额 } this.sum = total;// 把总金额复制给全局变量 sum } } //轿车 private MotoVehicle rentCar() { System.out.print("请输入轿车品牌:"); String brand = input.next(); System.out.print("请输入轿车车牌号:"); String carNumber = input.next(); System.out.print("请选择轿车类型[1、豪车 2、普通车:]"); int choise = input.nextInt(); String type; if (choise == 1) { type = "豪车"; } else { type = "普通型"; } return new Car(carNumber, brand, type); } //客车 private MotoVehicle rentBus() { System.out.print("请输入客车品牌:"); String brand = input.next(); System.out.print("请输入客车车牌号:"); String carNumber = input.next(); System.out.print("请输入客车座位数:"); int seatCount = input.nextInt(); return new Bus(carNumber, brand, seatCount); }}测试类:
package busTest;public class TestMain { public static void main(String[] args) { Customer customer = new Customer(); customer.showMenu(); }}以上是"Java如何实现汽车租赁系统"这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!
租赁
客车
轿车
汽车
金额
输入
对象
汽车租赁
品牌
类型
车牌
车牌号
系统
普通
天数
座位
方法
豪华
内容
座位数
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
数据库企业版fulluse
图形数据库软件
国际软件开发标准
委托软件开发费如何做账
软件开发公司的口碑
网络技术传播中心技术总监
畅捷通服务器登录不上去
IMS的新数据库DDD分级
浙江服务器存储云空间
静海区网络技术售后保障
绍兴施工管理软件开发
计算机网络安全实施细则
泉州市政法委网络安全宣传周活动
天水懒淘网络技术有限公司
与他人共享网络技术
阴阳师哪个服务器彩虹多
数据库安全防护魔力象限
保障网络安全对网监的效益
初中生物课件软件开发
微服务数据库架构设计方案
互联网科技服务商
数据库图形界面管理器
我国第一次提出网络安全法
自动拨号服务器设置
加强网络安全教育图片
网络安全是一个人独立的权利
四川广东网络安全培训
四川实用erp软件开发
崇明区工业软件开发费用
北京企业软件开发服务价格