java實(shí)現(xiàn)簡(jiǎn)單的汽車租賃系統(tǒng)
本文實(shí)例為大家分享了java實(shí)現(xiàn)簡(jiǎn)單的汽車租賃系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
歡迎進(jìn)入xx汽車租賃公司
請(qǐng)輸入用戶名
請(qǐng)輸入密碼
(用戶名默認(rèn)是名字縮寫,密碼是123,將登陸模塊封裝到方法中去調(diào)用方法)
請(qǐng)輸入您的操作
1)查看現(xiàn)在車庫中的所有車輛信息
2)租賃汽車
3)往車庫中添加汽車
4)修改汽車租賃價(jià)格信息
用switch去判斷操作
類分析
代碼:
package com.youjiuye.bms; public class CRMS { ?? ?public static void main(String[] args) { ?? ??? ?Wellcome(); ?? ?} ?? ?public static void Wellcome(){ ?? ??? ?System.out.println("***********************************"); ?? ??? ?System.out.println("\t歡迎來到何老板圖書館 ? ? ? ? ? ? ? ? ? ? ? ?"); ?? ??? ?System.out.println("***********************************"); ?? ??? ?// 獲取用戶信息 ?? ??? ?Tool.inputInfo(); ?? ?} }
package com.youjiuye.bms; /* ?* 汽車租賃系統(tǒng)的功能模塊類 ?* 1、管理員添加車庫中的車輛信息 ?* 2、用戶租賃車輛 ?* 3、用戶查看車庫中的車輛 ?* 4、用戶查看自己租賃的車輛 ?* 5、管理員修改車輛的價(jià)格 ?* 6、用戶結(jié)算租金 ?*/ public class CRMSService { ?? ?//?? ?1、管理員添加車庫中的車輛信息 ?? ?public boolean addVehicel(MotoVehicel mo){ ?? ??? ?boolean bo = false; ?? ??? ?MotoVehicel[] ms = MotoVehicel.getMs(); ?? ??? ?if(ms.length > 0){ ?? ??? ??? ? ?? ??? ??? ?for (int i = 0; i < ms.length; i++) { ?? ??? ??? ??? ?if(ms[i] == null){ ?? ??? ??? ??? ??? ?ms[i] = mo; ?? ??? ??? ??? ??? ?bo = true; ?? ??? ??? ??? ??? ?System.out.println("添加成功!"); ?? ??? ??? ??? ??? ?break; ?? ??? ??? ??? ?} ?? ??? ??? ?} ?? ??? ?} ?? ??? ?return bo; ?? ?} ?? ?//?? ? ?2、用戶租賃車輛 ?? ?public void rent(Users u,MotoVehicel mo){ ?? ??? ? ?? ??? ?MotoVehicel[] ms = u.getUms(); ?? ??? ?for (int i = 0; i < ms.length; i++) { ?? ??? ??? ?if(ms[i] ?== null){ ?? ??? ??? ??? ?ms[i] = mo; ?? ??? ??? ??? ?break; ?? ??? ??? ?} ?? ??? ?} ?? ?} ?? ?//?? ? ?4、用戶查看自己租賃的車輛 ?? ?public boolean browse(Users u){ ?? ??? ?boolean bo ?= false; ?? ??? ?MotoVehicel[] mo = u.getUms(); ?? ??? ?if(mo.length > 0){ ?? ??? ??? ? ?? ??? ??? ?for (int i = 0; i < mo.length; i++) { ?? ??? ??? ??? ?if(mo[i] != null){ ?? ??? ??? ??? ??? ?System.out.println(mo[i].toString()); ?? ??? ??? ??? ??? ?bo = true; ?? ??? ??? ??? ?} ?? ??? ??? ??? ? ?? ??? ??? ?} ?? ??? ?} ?? ??? ?return bo; ?? ??? ? ?? ?} ?? ?//?? ? ?5、管理員修改車輛的價(jià)格 ?? ?public boolean update(String no,double price){ ?? ??? ?boolean bo = false; ?? ??? ?if(MotoVehicel.arrayExit()){ ?? ??? ??? ? ?? ??? ??? ?MotoVehicel[] ms = MotoVehicel.getMs(); ?? ??? ??? ?for (int i = 0; i < ms.length; i++) { ?? ??? ??? ??? ?if(ms[i] != null && ms[i].getNo().equals(no)){ ?? ??? ??? ??? ??? ?ms[i].setRentPrice(price); ?? ??? ??? ??? ??? ?System.out.println("修改成功!"); ?? ??? ??? ??? ??? ?System.out.println(ms[i]); ?? ??? ??? ??? ??? ?bo = true; ?? ??? ??? ??? ?} ?? ??? ??? ?} ?? ??? ?}else{ ?? ??? ??? ?System.out.println("當(dāng)前車庫中還沒有車輛"); ?? ??? ?} ?? ??? ? ?? ??? ?return bo; ?? ?} ?? ?//?? ? ?6、用戶結(jié)算租金 ?? ?public double settleAccount(Users u,int days){ ?? ??? ?double price = 0; ?? ??? ?MotoVehicel[] mo = u.getUms(); ?? ??? ?if(mo.length > 0){?? ? ?? ??? ??? ?for (int i = 0; i < mo.length; i++) { ?? ??? ??? ??? ?if(mo[i] != null){ ?? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ?price += mo[i].getRentPrice() * days; ?? ??? ??? ??? ?} ?? ??? ??? ??? ? ?? ??? ??? ?} ?? ??? ?} ?? ??? ? ?? ??? ?return price; ?? ?} ?? ? ?? ?// 刪除車庫中的車輛 ?? ?public void delete(MotoVehicel moo){ ?? ??? ?MotoVehicel[] mo = MotoVehicel.getMs(); ?? ??? ?if(mo.length > 0){ ?? ??? ??? ?for (int i = 0; i < mo.length; i++) { ?? ??? ??? ??? ?if(mo[i] != null && mo[i].equals(moo)){ ?? ??? ??? ??? ??? ?mo[i] = null; ?? ??? ??? ??? ?} ?? ??? ??? ?} ?? ??? ?} ?? ??? ? ?? ?} ?? ? ?? ?// 根據(jù)車牌號(hào)來判斷車庫中是否含有該車輛 ?? ??? ??? ?public boolean judgeExitMotoVehicel(String no){ ?? ??? ??? ??? ?boolean bo = false; ?? ??? ??? ??? ?MotoVehicel[] ms = MotoVehicel.getMs(); ?? ??? ??? ??? ?if(ms.length >0){ ?? ??? ??? ??? ??? ?for (int i = 0; i < ms.length; i++) { ?? ??? ??? ??? ??? ??? ?if(ms[i].getNo().equals(no)){ ?? ??? ??? ??? ??? ??? ??? ?bo = true; ?? ??? ??? ??? ??? ??? ??? ?break; ?? ??? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ?} ?? ??? ??? ??? ?return bo; ?? ??? ??? ?} }
package com.youjiuye.bms; /* ?* 汽車租賃系統(tǒng)的功能模塊類 ?* 1、管理員添加車庫中的車輛信息 ?* 2、用戶租賃車輛 ?* 3、用戶查看車庫中的車輛 ?* 4、用戶查看自己租賃的車輛 ?* 5、管理員修改車輛的價(jià)格 ?* 6、用戶結(jié)算租金 ?*/ public class CRMSService { ?? ?//?? ?1、管理員添加車庫中的車輛信息 ?? ?public boolean addVehicel(MotoVehicel mo){ ?? ??? ?boolean bo = false; ?? ??? ?MotoVehicel[] ms = MotoVehicel.getMs(); ?? ??? ?if(ms.length > 0){ ?? ??? ??? ? ?? ??? ??? ?for (int i = 0; i < ms.length; i++) { ?? ??? ??? ??? ?if(ms[i] == null){ ?? ??? ??? ??? ??? ?ms[i] = mo; ?? ??? ??? ??? ??? ?bo = true; ?? ??? ??? ??? ??? ?System.out.println("添加成功!"); ?? ??? ??? ??? ??? ?break; ?? ??? ??? ??? ?} ?? ??? ??? ?} ?? ??? ?} ?? ??? ?return bo; ?? ?} ?? ?//?? ? ?2、用戶租賃車輛 ?? ?public void rent(Users u,MotoVehicel mo){ ?? ??? ? ?? ??? ?MotoVehicel[] ms = u.getUms(); ?? ??? ?for (int i = 0; i < ms.length; i++) { ?? ??? ??? ?if(ms[i] ?== null){ ?? ??? ??? ??? ?ms[i] = mo; ?? ??? ??? ??? ?break; ?? ??? ??? ?} ?? ??? ?} ?? ?} ?? ?//?? ? ?4、用戶查看自己租賃的車輛 ?? ?public boolean browse(Users u){ ?? ??? ?boolean bo ?= false; ?? ??? ?MotoVehicel[] mo = u.getUms(); ?? ??? ?if(mo.length > 0){ ?? ??? ??? ? ?? ??? ??? ?for (int i = 0; i < mo.length; i++) { ?? ??? ??? ??? ?if(mo[i] != null){ ?? ??? ??? ??? ??? ?System.out.println(mo[i].toString()); ?? ??? ??? ??? ??? ?bo = true; ?? ??? ??? ??? ?} ?? ??? ??? ??? ? ?? ??? ??? ?} ?? ??? ?} ?? ??? ?return bo; ?? ??? ? ?? ?} ?? ?//?? ? ?5、管理員修改車輛的價(jià)格 ?? ?public boolean update(String no,double price){ ?? ??? ?boolean bo = false; ?? ??? ?if(MotoVehicel.arrayExit()){ ?? ??? ??? ? ?? ??? ??? ?MotoVehicel[] ms = MotoVehicel.getMs(); ?? ??? ??? ?for (int i = 0; i < ms.length; i++) { ?? ??? ??? ??? ?if(ms[i] != null && ms[i].getNo().equals(no)){ ?? ??? ??? ??? ??? ?ms[i].setRentPrice(price); ?? ??? ??? ??? ??? ?System.out.println("修改成功!"); ?? ??? ??? ??? ??? ?System.out.println(ms[i]); ?? ??? ??? ??? ??? ?bo = true; ?? ??? ??? ??? ?} ?? ??? ??? ?} ?? ??? ?}else{ ?? ??? ??? ?System.out.println("當(dāng)前車庫中還沒有車輛"); ?? ??? ?} ?? ??? ? ?? ??? ?return bo; ?? ?} ?? ?//?? ? ?6、用戶結(jié)算租金 ?? ?public double settleAccount(Users u,int days){ ?? ??? ?double price = 0; ?? ??? ?MotoVehicel[] mo = u.getUms(); ?? ??? ?if(mo.length > 0){?? ? ?? ??? ??? ?for (int i = 0; i < mo.length; i++) { ?? ??? ??? ??? ?if(mo[i] != null){ ?? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ?price += mo[i].getRentPrice() * days; ?? ??? ??? ??? ?} ?? ??? ??? ??? ? ?? ??? ??? ?} ?? ??? ?} ?? ??? ? ?? ??? ?return price; ?? ?} ?? ? ?? ?// 刪除車庫中的車輛 ?? ?public void delete(MotoVehicel moo){ ?? ??? ?MotoVehicel[] mo = MotoVehicel.getMs(); ?? ??? ?if(mo.length > 0){ ?? ??? ??? ?for (int i = 0; i < mo.length; i++) { ?? ??? ??? ??? ?if(mo[i] != null && mo[i].equals(moo)){ ?? ??? ??? ??? ??? ?mo[i] = null; ?? ??? ??? ??? ?} ?? ??? ??? ?} ?? ??? ?} ?? ??? ? ?? ?} ?? ? ?? ?// 根據(jù)車牌號(hào)來判斷車庫中是否含有該車輛 ?? ??? ??? ?public boolean judgeExitMotoVehicel(String no){ ?? ??? ??? ??? ?boolean bo = false; ?? ??? ??? ??? ?MotoVehicel[] ms = MotoVehicel.getMs(); ?? ??? ??? ??? ?if(ms.length >0){ ?? ??? ??? ??? ??? ?for (int i = 0; i < ms.length; i++) { ?? ??? ??? ??? ??? ??? ?if(ms[i].getNo().equals(no)){ ?? ??? ??? ??? ??? ??? ??? ?bo = true; ?? ??? ??? ??? ??? ??? ??? ?break; ?? ??? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ?} ?? ??? ??? ??? ? ?? ??? ??? ??? ?return bo; ?? ??? ??? ?} }
package com.youjiuye.bms; public class Users { ?? ?private String identity; ?? ?private String password; ?? ? ?? ?// 存放租賃的車輛信息 ?? ?private MotoVehicel[] ums = new MotoVehicel[10]; ? ?? ? ?? ?public MotoVehicel[] getUms() { ?? ??? ?return ums; ?? ?} ?? ?public void setUms(MotoVehicel[] ums) { ?? ??? ?this.ums = ums; ?? ?} ?? ?public Users(){} ?? ?public Users(String identity, String password) { ?? ??? ?super(); ?? ??? ?this.identity = identity; ?? ??? ?this.password = password; ?? ?} ?? ?public String getIdentity() { ?? ??? ?return identity; ?? ?} ?? ?public void setIdentity(String identity) { ?? ??? ?this.identity = identity; ?? ?} ?? ?public String getPassword() { ?? ??? ?return password; ?? ?} ?? ?public void setPassword(String password) { ?? ??? ?this.password = password; ?? ?} ?? ?@Override ?? ?public String toString() { ?? ??? ?return "Users [identity=" + identity + ", password=" + password + "]"; ?? ?} }
package com.youjiuye.bms; /* ?* 所有車的父類 ?*? ?*/ public abstract class MotoVehicel { ?? ?private String no; ?? ?private String brand; ?? ?private String Color; ?? ?private int mileage; ?? ?private double rentPrice; ?? ?private static MotoVehicel[] ms= new MotoVehicel[10]; ?? ? ?? ? ?? ?public MotoVehicel(){} ?? ?public MotoVehicel(String no, String brand, String color, int mileage, double rentPrice) { ?? ??? ?super(); ?? ??? ?this.no = no; ?? ??? ?this.brand = brand; ?? ??? ?Color = color; ?? ??? ?this.mileage = mileage; ?? ??? ?this.rentPrice = rentPrice; ?? ?} ?? ?public String getNo() { ?? ??? ?return no; ?? ?} ?? ?public void setNo(String no) { ?? ??? ?this.no = no; ?? ?} ?? ?public String getBrand() { ?? ??? ?return brand; ?? ?} ?? ?public void setBrand(String brand) { ?? ??? ?this.brand = brand; ?? ?} ?? ?public String getColor() { ?? ??? ?return Color; ?? ?} ?? ?public void setColor(String color) { ?? ??? ?Color = color; ?? ?} ?? ?public int getMileage() { ?? ??? ?return mileage; ?? ?} ?? ?public void setMileage(int mileage) { ?? ??? ?this.mileage = mileage; ?? ?} ?? ?public double getRentPrice() { ?? ??? ?return rentPrice; ?? ?} ?? ?public void setRentPrice(double rentPrice) { ?? ??? ?this.rentPrice = rentPrice; ?? ?} ?? ? ?? ?// 獲取車庫數(shù)組 ?? ?public static MotoVehicel[] getMs() { ?? ??? ?return ms; ?? ?} ?? ? ?? ?// 租賃功能 ?? ?public abstract double rent(int days); ?? ? ?? ?// 初始化車庫數(shù)組 ?? ?public static final void init(){ ?? ??? ?Car c1 = new Car("001", "bwm","藍(lán)色",10000, 500,"x5"); ?? ??? ?ms[0] = c1; ?? ??? ?Bus b1 = new Bus("8567", "景龍", "綠色",2000, 800,16); ?? ??? ?ms[1] = b1; ?? ?} ?? ? ?? ?// 判斷當(dāng)前車庫是否有車存在 ?? ?public static boolean arrayExit(){ ?? ??? ?boolean bo = false; ?? ??? ?if(ms.length > 0){ ?? ??? ??? ?for (int i = 0; i < ms.length; i++) { ?? ??? ??? ??? ?if(ms[i] != null){ ?? ??? ??? ??? ??? ?bo = true; ?? ??? ??? ??? ?} ?? ??? ??? ?} ?? ??? ?}else{ ?? ??? ??? ?bo = false; ?? ??? ?} ?? ??? ?return bo; ?? ??? ? ?? ?} ?? ? ?? ?// 顯示車庫中現(xiàn)有的車輛 ?? ?public static void show(){ ?? ??? ?System.out.println("當(dāng)前車庫的車:"); ?? ??? ?if(arrayExit()){ ?? ??? ??? ?for (int i = 0; i < ms.length; i++) { ?? ??? ??? ??? ?if(ms[i] != null){ ?? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ?System.out.println(ms[i]); ?? ??? ??? ??? ?} ?? ??? ??? ?} ?? ??? ?}else{ ?? ??? ??? ?System.out.println("當(dāng)前車庫中沒有車輛"); ?? ??? ?} ?? ??? ? ?? ?} ?? ?? }
```java package com.youjiuye.bms; /* ?* 公交車 ?*/ public class Bus extends MotoVehicel{ ?? ?private int seatCount; ?? ? ?? ?public Bus(){} ?? ?public Bus(String no, String brand, String color, int mileage, double rentPrice,int seatCount) { ?? ??? ?super(no, brand, color, mileage, rentPrice); ?? ??? ?this.seatCount = seatCount;?? ? ?? ?} ?? ?public int getSeatCount() { ?? ??? ?return seatCount; ?? ?} ?? ?public void setSeatCount(int seatCount) { ?? ??? ?this.seatCount = seatCount; ?? ?} ?? ? ?? ?@Override ?? ?public String toString() { ?? ??? ?return "Bus [ 車牌號(hào):"+ getNo()+"\t品牌:"+getBrand()+"\t座位數(shù):"+getSeatCount()+"\t顏色:"+ getColor()+"\t里程:"+getMileage()+"\t日租價(jià):"+getRentPrice()+ "]"; ?? ?} ?? ?@Override ?? ?public double rent(int days) { ?? ??? ? ?? ??? ?return days * getRentPrice(); ?? ?} ?? ? }
package com.youjiuye.bms; /* ?* 小轎車 ?*/ public class Car extends MotoVehicel{ ?? ?private String type; ?? ? ?? ?public Car(){} ?? ?public Car(String no, String brand, String color, int mileage, double rentPrice,String type) { ?? ??? ?super(no, brand, color, mileage, rentPrice); ?? ??? ?this.type = type;?? ? ?? ?} ?? ?public String getType() { ?? ??? ?return type; ?? ?} ?? ?public void setType(String type) { ?? ??? ?this.type = type; ?? ?} ?? ? ?? ?@Override ?? ?public String toString() { ?? ??? ?return "Car [ 車牌號(hào): "+ getNo()+"\t品牌:"+getBrand()+"\t型號(hào):"+getType()+"\t顏色:"+ getColor()+"\t里程:"+getMileage()+"\t日租價(jià):"+getRentPrice()+ "]"; ?? ?} ?? ?@Override ?? ?public double rent(int days) { ?? ??? ? ?? ??? ?return days * getRentPrice(); ?? ?} }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Java?Git?Commit?Message使用規(guī)范
這篇文章主要介紹了Java?Git?Commit?Message使用規(guī)范,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,感興趣的小伙伴可以參考一下,希望對(duì)你的學(xué)習(xí)有所幫助2022-08-08詳解spring boot 以jar的方式啟動(dòng)常用shell腳本
本篇文章主要介紹了詳解spring boot 以jar的方式啟動(dòng)常用shell腳本,具有一定的參考價(jià)值,有興趣的可以了解一下2017-09-09Spring實(shí)戰(zhàn)之Qualifier注解用法示例
這篇文章主要介紹了Spring實(shí)戰(zhàn)之Qualifier注解用法,結(jié)合實(shí)例形式詳細(xì)分析了spring Qualifier注解相關(guān)配置、定義與使用方法,需要的朋友可以參考下2019-12-12詳解rabbitmq創(chuàng)建queue時(shí)arguments參數(shù)注釋
這篇文章主要介紹了rabbitmq創(chuàng)建queue時(shí)arguments參數(shù)注釋,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-03-03Java 讀取網(wǎng)絡(luò)圖片存儲(chǔ)到本地并生成縮略圖
用Java做開發(fā)經(jīng)常需要處理圖片。本文就來看一下如何保存圖片到本地并生成縮略圖2021-05-05Mybatis動(dòng)態(tài)sql超詳細(xì)講解
動(dòng)態(tài)SQL是MyBatis的強(qiáng)大特性之一,顧名思義就是會(huì)動(dòng)的SQL,即是能夠靈活的根據(jù)某種條件拼接出完整的SQL語句,下面這篇文章主要給大家介紹了關(guān)于Mybatis動(dòng)態(tài)sql的相關(guān)資料,需要的朋友可以參考下2023-04-04springboot @Controller和@RestController的區(qū)別及應(yīng)用詳解
這篇文章主要介紹了springboot @Controller和@RestController的區(qū)別及應(yīng)用,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-11-11