最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

java實(shí)現(xiàn)汽車租賃系統(tǒng)

 更新時(shí)間:2021年01月20日 09:18:37   作者:妖精小狗  
這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)汽車租賃系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了java實(shí)現(xiàn)汽車租賃系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

//車類
public abstract class Vehicle {
 //車牌號(hào) 品牌 日租金
 private String id;
 private String brand;
 private int perRent;
 
 public Vehicle(){}
 //Vehicle的帶參構(gòu)造方法
 public Vehicle(String id, String brand, int perRent) {
 this.id = id;
 this.brand = brand;
 this.perRent = perRent;
 }
 
 public void setId(String id){
 this.id=id ;
 }
 public String getId(){
 return id;
 }
 
 public void setBrand(String brand){
 this.brand=brand;
 }
 public String getBrand(){
 return brand;
 }
 
 public void setPerRent(int perRent){
 this.perRent=perRent;
 }
 public int getPerRent(){
 return perRent;
 }
 //抽象方法計(jì)算租金
 public abstract double calcRent(int days);
 
}
 
//轎車類
public class Car extends Vehicle{
 //型號(hào)
 private String type;
 public void setType(String type){
 this.type=type;
 }
 public String getType(){
 return type;
 }
 
 public Car(){}
 //Car的帶參構(gòu)造方法
 public Car(String id, String brand, int perRent,String type) {
 super(id,brand,perRent);
 this.type = type;
 }
 //重寫父類的計(jì)算租金方法:根據(jù)自己的計(jì)算租金規(guī)則
 public double calcRent(int days) {
 double price = this.getPerRent()*days;
 if(days>7 && days<=30){
 price *= 0.9;
 }else if(days>30 && days<=150){
 price *= 0.8;
 }else if(days>150){
 price *= 0.7;
 }
 return price;
 }
}
 
//客車類
public class Bus extends Vehicle{
 //座位數(shù)
 private int seatCount;
 public void setSeatCount(int seatCount){
 this.seatCount=seatCount;
 }
 public int getSeatCount(){
 return seatCount;
 }
 
 
 public Bus(){}
 //Bus的帶參構(gòu)造方法
 public Bus(String id,String brand,int perRent,int seatCount){
 super(id,brand,perRent);
 this.seatCount = seatCount;
 }
 //重寫父類的計(jì)算租金方法:根據(jù)自己的計(jì)算租金規(guī)則
 public double calcRent(int days) {
 double price = this.getPerRent()*days;
 if(days>=3 && days<7){
 price *= 0.9;
 }else if(days>=7 && days<30){
 price *= 0.8;
 }else if(days>=30 && days<150){
 price *= 0.7;
 }else if(days>150){
 price *= 0.6;
 }
 return price;
 
 }
}
 
//汽車業(yè)務(wù)類
public class Operation {
 public Vehicle[] vehicle = new Vehicle[8];
//初始化汽車信息
 public void init(){
 vehicle[0] = new Car("京NY28588","寶馬",800,"X6"); //vehicle v = new Car();
 vehicle[1] = new Car("京CNY32584","寶馬",600,"550i"); //vehicle v = new Car();
 vehicle[2] = new Car("京NT37465","別克",300,"林蔭大道"); //vehicle v = new Car();
 vehicle[3] = new Car("京NT96968","別克",600,"GL8"); //vehicle v = new Car();
 vehicle[4] = new Bus("京6566754","金杯",800,16); //vehicle v = new Bus();
 vehicle[5] = new Bus("京8696997","金龍",800,16); //vehicle v = new Bus();
 vehicle[6] = new Bus("京9696996","金杯",1500,34); //vehicle v = new Bus();
 vehicle[7] = new Bus("京8696998","金龍",1500,34); //vehicle v = new Bus();
 }
 //租車:根據(jù)用戶提供的條件去汽車數(shù)組中查找相應(yīng)車輛并返回
 //如果租賃的是轎車 需要條件:品牌  型號(hào)
 //如果租賃的是客車 需要條件:品牌  座位數(shù)
 //簡單工廠模式
 public Vehicle zuChe(String brand,String type,int seatCount){
 Vehicle che = null;
 //for循環(huán)遍歷數(shù)組vehicle
 for(Vehicle myche : vehicle){
 //判斷Vehicle類的myche的類型是否和Car一樣
 if(myche instanceof Car){
 //Vehicle類的myche向下轉(zhuǎn)型變成子類Car
 Car car = (Car)myche;
 if(car.getBrand().equals(brand) && car.getType().equals(type)){
  che=car;
  break;
 }
 }else{
 //Vehicle類的myche向下轉(zhuǎn)型變成子類Bus
 Bus bus = (Bus)myche;
 if(bus.getBrand().equals(brand) && bus.getSeatCount() == seatCount){
  che=bus;
  break;
 }
 }
 }
 return che;
 
 }
}
 
//汽車租賃
public class Rent {
 public static void main(String[] args) {
 Scanner input = new Scanner(System.in);
 Operation operation = new Operation();
 //租賃公司界面
 operation.init();
 System.out.println("**********歡迎光臨租賃公司**********");
 System.out.println("1.轎車\t\t2.客車");
 System.out.println("請(qǐng)選擇您要租賃的汽車類型:(1.轎車 2.客車)");
 int cheType = input.nextInt();
 String brand = "";//品牌
 String type = "";//型號(hào)
 int seatCount = 0;//座位數(shù)
 //收集用戶條件
 if(cheType == 1){
 //租賃轎車
 System.out.println("請(qǐng)選擇您要租賃的轎車品牌:(1.別克 2.寶馬)");
 int choose = input.nextInt();
 if(choose == 1){
 brand="別克";
 System.out.println("請(qǐng)選擇您要租賃的汽車型號(hào):(1.林蔭大道 2.GL8)");
 type=(input.nextInt() == 1)?"林蔭大道":"GL8";
 }else if(choose == 2){
 brand="寶馬";
 System.out.println("請(qǐng)選擇您要租賃的汽車型號(hào):(1.X6 2.550i)");
 type=(input.nextInt() == 1)?"X6":"550i";
 }
 
 }else if(cheType == 2){
 //租賃客車
 type= "";
 System.out.println("請(qǐng)選擇您要租賃的客車品牌:(1.金杯 2.金龍)");
 brand=(input.nextInt()==1)?"金杯":"金龍";
 System.out.println("請(qǐng)選擇您要租賃的客車座位數(shù):(1.16座 2.32座)");
 seatCount=(input.nextInt() == 1)?16:34;
 }
 //租車
 Vehicle che = operation.zuChe(brand, type, seatCount);
 System.out.println("請(qǐng)輸入您的租賃天數(shù):");
 int days = input.nextInt();
 double money = che.calcRent(days);
 System.out.println("租車成功,請(qǐng)按照如下車牌號(hào)提車:"+che.getId());
 System.out.println("您需要支付:"+money+"元");
 }
 
}

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • RepeatSubmit若依框架如何防止表單重復(fù)提交注解

    RepeatSubmit若依框架如何防止表單重復(fù)提交注解

    若依框架中的@RepeatSubmit注解用于防止表單重復(fù)提交,通過在控制器方法上添加該注解,并在前端頁面和JavaScript代碼中實(shí)現(xiàn)雙重校驗(yàn),可以確保同一用戶在短時(shí)間內(nèi)不會(huì)重復(fù)提交相同的表單
    2024-11-11
  • Java使用正則表達(dá)式刪除所有HTML標(biāo)簽的方法示例

    Java使用正則表達(dá)式刪除所有HTML標(biāo)簽的方法示例

    這篇文章主要介紹了Java使用正則表達(dá)式刪除所有HTML標(biāo)簽的方法,結(jié)合完整實(shí)例形式分析了java針對(duì)HTML頁面元素script標(biāo)簽、style標(biāo)簽、html標(biāo)簽等的正則匹配相關(guān)操作技巧,需要的朋友可以參考下
    2017-06-06
  • Java壓縮文件工具類ZipUtil使用方法代碼示例

    Java壓縮文件工具類ZipUtil使用方法代碼示例

    這篇文章主要介紹了Java壓縮文件工具類ZipUtil使用方法代碼示例,具有一定借鑒價(jià)值,需要的朋友可以參考下。
    2017-11-11
  • Java指令重排在多線程環(huán)境下的解決方式

    Java指令重排在多線程環(huán)境下的解決方式

    這篇文章介紹了Java指令重排在多線程環(huán)境下的解決方式,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-04-04
  • idea創(chuàng)建maven父子工程導(dǎo)致子工程無法導(dǎo)入父工程依賴

    idea創(chuàng)建maven父子工程導(dǎo)致子工程無法導(dǎo)入父工程依賴

    創(chuàng)建maven父子工程時(shí)遇到一個(gè)問題,本文主要介紹了idea創(chuàng)建maven父子工程導(dǎo)致子工程無法導(dǎo)入父工程依賴,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-04-04
  • MybatisPlus特殊查詢的實(shí)現(xiàn)介紹

    MybatisPlus特殊查詢的實(shí)現(xiàn)介紹

    這篇文章主要介紹了MybatisPlus查詢投影、聚合查詢、分組查詢、等值查詢、范圍查詢、模糊查詢、排序查詢,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧
    2022-10-10
  • idea生成類注釋和方法注釋的正確方法(推薦)

    idea生成類注釋和方法注釋的正確方法(推薦)

    這篇文章主要介紹了idea生成類注釋和方法注釋的正確方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-11-11
  • MyBatis中模糊查詢使用CONCAT('%',#{str},'%')出錯(cuò)的解決

    MyBatis中模糊查詢使用CONCAT('%',#{str},'%')出錯(cuò)的解

    這篇文章主要介紹了MyBatis中模糊查詢使用CONCAT('%',#{str},'%')出錯(cuò)的解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-01-01
  • Spring boot使用logback實(shí)現(xiàn)日志管理過程詳解

    Spring boot使用logback實(shí)現(xiàn)日志管理過程詳解

    這篇文章主要介紹了Spring boot使用logback實(shí)現(xiàn)日志管理過程詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-06-06
  • 詳解SpringBoot中@PostMapping注解的用法

    詳解SpringBoot中@PostMapping注解的用法

    在SpringBoot中,我們經(jīng)常需要編寫RESTful Web服務(wù),以便于客戶端與服務(wù)器之間的通信,@PostMapping注解可以讓我們更方便地編寫POST請(qǐng)求處理方法,在本文中,我們將介紹@PostMapping注解的作用、原理,以及如何在SpringBoot應(yīng)用程序中使用它
    2023-06-06

最新評(píng)論

佛冈县| 弥渡县| 沅江市| 临夏县| 酉阳| 樟树市| 安丘市| 锡林郭勒盟| 永川市| 潞城市| 二连浩特市| 岳普湖县| 江山市| 肃南| 越西县| 来宾市| 崇义县| 抚宁县| 图木舒克市| 黔西县| 梅州市| 平度市| 青海省| 华宁县| 凤山县| 石嘴山市| 皮山县| 南召县| 子洲县| 麻江县| 油尖旺区| 政和县| 满城县| 城步| 保山市| 新闻| 绥宁县| 乐至县| 濉溪县| 西乡县| 大名县|