原來Java實(shí)現(xiàn)簡單汽車租賃系統(tǒng)這么容易

這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)簡單汽車租賃系統(tǒng),文中示例代碼介紹的非常詳細(xì)侠驯,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了java實(shí)現(xiàn)汽車租賃系統(tǒng)的具體代碼劫乱,供大家參考巡李,具體內(nèi)容如下

一、使用技術(shù)
javaSE

二笆呆、實(shí)現(xiàn)功能
汽車租賃系統(tǒng)

具體要求如下:

使用面向?qū)ο蟮闹R實(shí)現(xiàn)一個(gè)汽車租賃系統(tǒng)

1.汽車租賃信息表如下


2.類和屬性

三请琳、運(yùn)行效果圖

1.先創(chuàng)建一個(gè)汽車類作為父類粱挡,這里有汽車的公共屬性:

public class Automobile {//汽車類
  private String licensePlate;//車牌
  private String brand;//品牌
  private int rent;//租金
 
  public Automobile() {
  }
 
  public Automobile(String licensePlate, String brand, int rent) {
    this.licensePlate = licensePlate;
    this.brand = brand;
    this.rent = rent;
  }
 
  public String getLicensePlate() {
    return licensePlate;
  }
 
  public void setLicensePlate(String licensePlate) {
    this.licensePlate = licensePlate;
  }
 
  public String getBrand() {
    return brand;
  }
 
  public void setBrand(String brand) {
    this.brand = brand;
  }
 
  public int getRent() {
    return rent;
  }
 
  public void setRent(int rent) {
    this.rent = rent;
  }
}

2.創(chuàng)建一個(gè)轎車類,繼承汽車類的屬性

public class Car extends Automobile{//轎車
  private String model;//型號
 
  public Car(String model) {
    this.model = model;
  }
 
  public Car(String licensePlate, String brand, int rent, String model) {
    super(licensePlate, brand, rent);
    this.model = model;
  }
 
  public String getModel() {
    return model;
  }
 
  public void setModel(String model) {
    this.model = model;
  }
}

3.創(chuàng)建一個(gè)客車類俄精,繼承汽車類的屬性

public class Passengercar extends Automobile{//客車
private String seatingCapacity;//座位數(shù)
 
  public Passengercar(String seatingCapacity) {
    this.seatingCapacity = seatingCapacity;
  }
 
  public Passengercar(String licensePlate, String brand, int rent, String seatingCapacity) {
    super(licensePlate, brand, rent);
    this.seatingCapacity = seatingCapacity;
  }
 
  public String getSeatingCapacity() {
    return seatingCapacity;
  }
 
  public void setSeatingCapacity(String seatingCapacity) {
    this.seatingCapacity = seatingCapacity;
  }
}

4.創(chuàng)建測試類询筏,用于實(shí)現(xiàn)這個(gè)系統(tǒng)

import java.util.Scanner;
 
public class TestAutomobile {
  public static void main(String[] args) {
 
 
    Car c1 = new Car("京NY28588", "寶馬X6", 800, "1");
    Car c2 = new Car("京CNY3284", "寶馬550i", 600, "1");
    Car c3 = new Car("京NT37465", "別克林蔭大道", 300, "1");
    Car c4 = new Car("京NT969968", "別克GL8", 600, "1");
 
    Passengercar p1 = new Passengercar("京6566754", "金杯,16座", 800, "2");
    Passengercar p2 = new Passengercar("京8696997", "金龍,16座", 800, "2");
    Passengercar p3 = new Passengercar("京9696996", "金杯,34座", 1500, "2");
    Passengercar p4 = new Passengercar("京8696998", "金龍,34座", 1500, "2");
    Scanner sc = new Scanner(System.in);
 
    System.out.println("***********************歡迎光臨秋名山守望者汽車租賃公司***********************");
    while (true){
      System.out.println("1竖慧、轎車  2嫌套、客車");
      System.out.println("請選擇你要租賃的汽車類型:");
      String a=sc.next();
      if (a.equals("1")){//轎車
        System.out.println("請選擇你要租賃的汽車品牌:1、別克 2圾旨、寶馬");
        String a1=sc.next();
        if (a1.equals("2")){//寶馬
          System.out.println("請選擇你要租賃的汽車類型:1踱讨、X6 2、550i");
          String a2=sc.next();
          if (a2.equals("2")){//550i
            System.out.println("請選擇你要租賃的天數(shù)");
            double a3=sc.nextInt();
            System.out.println("分配給您的汽車牌號是:"+c2.getLicensePlate());
            System.out.print("您需要支付的租賃費(fèi)用是:");
            if (a3>7&&a3<=30){
              System.out.println(c2.getRent()*a3*0.9+"元");
            }else if(a3>30&&a3<=150){
              System.out.println(c2.getRent()*a3*0.8+"元");
            }else {
              System.out.println(c2.getRent()*a3*0.7+"元");
            }
          }else {//x6
            System.out.println("請選擇你要租賃的天數(shù)");
            double a3=sc.nextInt();
            System.out.println("分配給您的汽車牌號是:"+c1.getLicensePlate());
            System.out.print("您需要支付的租賃費(fèi)用是:");
            if (a3>7&&a3<=30){
              System.out.println(c1.getRent()*a3*0.9+"元");
            }else if(a3>30&&a3<=150){
              System.out.println(c1.getRent()*a3*0.8+"元");
            }else {
              System.out.println(c1.getRent()*a3*0.7+"元");
            }
          }
        }else {//別克
          System.out.println("請選擇你要租賃的汽車類型:1砍的、林蔭大道 2痹筛、GL8");
          String a2=sc.next();
          if (a2.equals("2")){//GL8
            System.out.println("請選擇你要租賃的天數(shù)");
            double a3=sc.nextInt();
            System.out.println("分配給您的汽車牌號是:"+c4.getLicensePlate());
            System.out.print("您需要支付的租賃費(fèi)用是:");
            if (a3>7&&a3<=30){
              System.out.println(c4.getRent()*a3*0.9+"元");
            }else if(a3>30&&a3<=150){
              System.out.println(c4.getRent()*a3*0.8+"元");
            }else {
              System.out.println(c4.getRent()*a3*0.7+"元");
            }
          }else {//別克林蔭大道
            System.out.println("請選擇你要租賃的天數(shù)");
            double a3=sc.nextInt();
            System.out.println("分配給您的汽車牌號是:"+c3.getLicensePlate());
            System.out.print("您需要支付的租賃費(fèi)用是:");
            if (a3>7&&a3<=30){
              System.out.println(c3.getRent()*a3*0.9+"元");
            }else if(a3>30&&a3<=150){
              System.out.println(c3.getRent()*a3*0.8+"元");
            }else {
              System.out.println(c3.getRent()*a3*0.7+"元");
            }
          }
        }
 
 
     /* Passengercar p1 = new Passengercar("京6566754", "金杯", 800, "2");
      Passengercar p2 = new Passengercar("京8696997", "金龍", 800, "2");
      Passengercar p3 = new Passengercar("京9696996", "金杯", 1500, "2");
      Passengercar p4 = new Passengercar("京8696998", "金龍", 1500, "2");
*/
      }else {//客車
        System.out.println("請選擇你要租賃的汽車品牌:1、金龍 2挨约、金杯");
        String a1=sc.next();
        if (a1.equals("1")){//金龍
          System.out.println("請選擇你要租賃的汽車座位數(shù):1味混、16座 2、34座");
          String a2=sc.next();
          if (a2.equals("1")){//16座
            System.out.println("請選擇你要租賃的天數(shù)");
            double a3=sc.nextInt();
            System.out.println("分配給您的汽車牌號是:"+p2.getLicensePlate());
            System.out.print("您需要支付的租賃費(fèi)用是:");
            if (a3>=3&&a3<7){
              System.out.println(p2.getRent()*a3*0.9+"元");
            }else if(a3>=7&&a3<30){
              System.out.println(p2.getRent()*a3*0.8+"元");
            }else if (a3>=30&&a3<150){
              System.out.println(p2.getRent()*a3*0.7+"元");
            }else {
              System.out.println(p2.getRent()*a3*0.6+"元");
            }
          }else {//34
            System.out.println("請選擇你要租賃的天數(shù)");
            double a3=sc.nextInt();
            System.out.println("分配給您的汽車牌號是:"+p4.getLicensePlate());
            System.out.print("您需要支付的租賃費(fèi)用是:");
            if (a3>=3&&a3<7){
              System.out.println(p4.getRent()*a3*0.9+"元");
            }else if(a3>=7&&a3<30){
              System.out.println(p4.getRent()*a3*0.8+"元");
            }else if (a3>=30&&a3<150){
              System.out.println(p4.getRent()*a3*0.7+"元");
            }else {
              System.out.println(p4.getRent()*a3*0.6+"元");
            }
          }
        }else {//金杯
          System.out.println("請選擇你要租賃的汽車座位數(shù):1诫惭、16座 2翁锡、34座");
          String a2=sc.next();
          if (a2.equals("1")){//16座
            System.out.println("請選擇你要租賃的天數(shù)");
            double a3=sc.nextInt();
            System.out.println("分配給您的汽車牌號是:"+p1.getLicensePlate());
            System.out.print("您需要支付的租賃費(fèi)用是:");
            if (a3>=3&&a3<7){
              System.out.println(p1.getRent()*a3*0.9+"元");
            }else if(a3>=7&&a3<30){
              System.out.println(p1.getRent()*a3*0.8+"元");
            }else if (a3>=30&&a3<150){
              System.out.println(p1.getRent()*a3*0.7+"元");
            }else {
              System.out.println(p1.getRent()*a3*0.6+"元");
            }
          }else {//34
            System.out.println("請選擇你要租賃的天數(shù)");
            double a3=sc.nextInt();
            System.out.println("分配給您的汽車牌號是:"+p3.getLicensePlate());
            System.out.print("您需要支付的租賃費(fèi)用是:");
            if (a3>=3&&a3<7){
              System.out.println(p3.getRent()*a3*0.9+"元");
            }else if(a3>=7&&a3<30){
              System.out.println(p3.getRent()*a3*0.8+"元");
            }else if (a3>=30&&a3<150){
              System.out.println(p3.getRent()*a3*0.7+"元");
            }else {
              System.out.println(p3.getRent()*a3*0.6+"元");
            }
          }
        }
 
      }
      System.out.println();
      System.out.println();
      System.out.println("是否還要繼續(xù)選車 1繼續(xù) 2終止");
      String x=sc.next();
      if (x.equals("2")){
        System.out.println("歡迎下次光臨!");
        break;
      }
      System.out.println();
      System.out.println();
    }
 
 
  }
 
}

1.轎車的實(shí)現(xiàn)


2.客車的實(shí)現(xiàn)

以上就是本文的全部內(nèi)容夕土,希望對大家的學(xué)習(xí)有所幫助馆衔,也希望大家多多支持小編

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末怨绣,一起剝皮案震驚了整個(gè)濱河市角溃,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌篮撑,老刑警劉巖减细,帶你破解...
    沈念sama閱讀 218,386評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異赢笨,居然都是意外死亡未蝌,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,142評論 3 394
  • 文/潘曉璐 我一進(jìn)店門茧妒,熙熙樓的掌柜王于貴愁眉苦臉地迎上來萧吠,“玉大人,你說我怎么就攤上這事桐筏≈叫停” “怎么了?”我有些...
    開封第一講書人閱讀 164,704評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長狰腌。 經(jīng)常有香客問我除破,道長,這世上最難降的妖魔是什么癌别? 我笑而不...
    開封第一講書人閱讀 58,702評論 1 294
  • 正文 為了忘掉前任皂岔,我火速辦了婚禮,結(jié)果婚禮上展姐,老公的妹妹穿的比我還像新娘躁垛。我一直安慰自己,他們只是感情好圾笨,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,716評論 6 392
  • 文/花漫 我一把揭開白布教馆。 她就那樣靜靜地躺著,像睡著了一般擂达。 火紅的嫁衣襯著肌膚如雪土铺。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,573評論 1 305
  • 那天板鬓,我揣著相機(jī)與錄音悲敷,去河邊找鬼。 笑死俭令,一個(gè)胖子當(dāng)著我的面吹牛后德,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播抄腔,決...
    沈念sama閱讀 40,314評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼瓢湃,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了赫蛇?” 一聲冷哼從身側(cè)響起绵患,我...
    開封第一講書人閱讀 39,230評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎悟耘,沒想到半個(gè)月后落蝙,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,680評論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡暂幼,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,873評論 3 336
  • 正文 我和宋清朗相戀三年掘殴,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片粟誓。...
    茶點(diǎn)故事閱讀 39,991評論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖起意,靈堂內(nèi)的尸體忽然破棺而出鹰服,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 35,706評論 5 346
  • 正文 年R本政府宣布悲酷,位于F島的核電站套菜,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏设易。R本人自食惡果不足惜逗柴,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,329評論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望顿肺。 院中可真熱鬧戏溺,春花似錦、人聲如沸屠尊。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,910評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽讼昆。三九已至托享,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間浸赫,已是汗流浹背闰围。 一陣腳步聲響...
    開封第一講書人閱讀 33,038評論 1 270
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留既峡,地道東北人羡榴。 一個(gè)月前我還...
    沈念sama閱讀 48,158評論 3 370
  • 正文 我出身青樓,卻偏偏與公主長得像涧狮,于是被迫代替她去往敵國和親炕矮。 傳聞我的和親對象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,941評論 2 355

推薦閱讀更多精彩內(nèi)容