亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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)文章

  • SpringBoot快速入門及起步依賴解析(實(shí)例詳解)

    SpringBoot快速入門及起步依賴解析(實(shí)例詳解)

    SpringBoot?是由?Pivotal?團(tuán)隊(duì)提供的全新框架,其設(shè)計(jì)目的是用來簡化?Spring?應(yīng)用的初始搭建以及開發(fā)過程,這篇文章主要介紹了SpringBoot快速入門及起步依賴解析,需要的朋友可以參考下
    2022-10-10
  • java ant包中的org.apache.tools.zip實(shí)現(xiàn)壓縮和解壓縮實(shí)例詳解

    java ant包中的org.apache.tools.zip實(shí)現(xiàn)壓縮和解壓縮實(shí)例詳解

    這篇文章主要介紹了java ant包中的org.apache.tools.zip實(shí)現(xiàn)壓縮和解壓縮實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下
    2017-04-04
  • JAVAEE項(xiàng)目結(jié)構(gòu)以及并發(fā)隨想

    JAVAEE項(xiàng)目結(jié)構(gòu)以及并發(fā)隨想

    每個(gè)代碼里面的工具都是工具,API是你最需要理解的,哪個(gè)好,哪個(gè)不好,沒有準(zhǔn)確答案。 一切皆對(duì)象,對(duì)于Java來講是純粹的,代理是對(duì)象,反射是對(duì)象,對(duì)象是對(duì)象,基本數(shù)據(jù)類型不是對(duì)象。
    2016-04-04
  • 詳解JAVA中使用FTPClient工具類上傳下載

    詳解JAVA中使用FTPClient工具類上傳下載

    這篇文章主要介紹了JAVA中使用FTPClient工具類上傳下載的相關(guān)資料,java 使用FTP服務(wù)器上傳文件、下載文件,需要的朋友可以參考下
    2017-08-08
  • 詳解Java回調(diào)的原理與實(shí)現(xiàn)

    詳解Java回調(diào)的原理與實(shí)現(xiàn)

    回調(diào)函數(shù),顧名思義,用于回調(diào)的函數(shù)?;卣{(diào)函數(shù)只是一個(gè)功能片段,由用戶按照回調(diào)函數(shù)調(diào)用約定來實(shí)現(xiàn)的一個(gè)函數(shù)。回調(diào)函數(shù)是一個(gè)工作流的一部分,由工作流來決定函數(shù)的調(diào)用(回調(diào))時(shí)機(jī)。
    2017-03-03
  • SpringBoot通過ip獲取歸屬地的幾種方式分享

    SpringBoot通過ip獲取歸屬地的幾種方式分享

    在日常我們逛網(wǎng)站的時(shí)候會(huì)發(fā)現(xiàn)我們登錄后會(huì)出現(xiàn)歸屬地信息,例如:我在廣州登錄會(huì)顯示廣東廣州,有些更加精確的會(huì)顯示到區(qū)縣,那么我們來看看有哪些方式來獲取歸屬地信息,今天我們來聊一聊
    2023-09-09
  • Java實(shí)現(xiàn)微信公眾號(hào)發(fā)送模版消息

    Java實(shí)現(xiàn)微信公眾號(hào)發(fā)送模版消息

    大家好,本篇文章主要講的是Java實(shí)現(xiàn)微信公眾號(hào)發(fā)送模版消息,感興趣的同學(xué)趕快來看一看吧,對(duì)你有幫助的話記得收藏一下
    2022-01-01
  • 2020版IDEA整合GitHub的方法詳解

    2020版IDEA整合GitHub的方法詳解

    這篇文章主要介紹了2020版IDEA整合GitHub的方法,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-08-08
  • Spring BeanDefinition使用介紹

    Spring BeanDefinition使用介紹

    BeanDefinition是Spring框架中非常核心的概念,BeanDefinition是定義Bean的配置元信息接口,Spring根據(jù)BeanDefinition來定義Bean對(duì)象,簡單說就是對(duì)Bean信息的定義
    2023-01-01
  • SpringBoot實(shí)現(xiàn)redis延遲隊(duì)列的示例代碼

    SpringBoot實(shí)現(xiàn)redis延遲隊(duì)列的示例代碼

    延時(shí)隊(duì)列場景在我們?nèi)粘I(yè)務(wù)開發(fā)中經(jīng)常遇到,它是一種特殊類型的消息隊(duì)列,本文就來介紹一下SpringBoot實(shí)現(xiàn)redis延遲隊(duì)列的示例代碼,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-02-02

最新評(píng)論