欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Java面向?qū)ο髮崿F(xiàn)汽車租賃系統(tǒng)

 更新時間:2022年02月24日 10:21:48   作者:勤奮的小鎮(zhèn)青年、  
這篇文章主要為大家詳細(xì)介紹了Java面向?qū)ο髮崿F(xiàn)汽車租賃系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

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

父類Vehicle

public abstract class Vehicle {
? ? private String num;
? ? private String brand;
? ? private ?double rent;

? ? //重寫equals方法
? ? public abstract boolean equals(Vehicle v);

? ? //計算費用
? ? public abstract double cost(int days,double rent);

? ? //3個參數(shù)的有參構(gòu)造
? ? public Vehicle(String num, String brand, double rent) {
? ? ? ? this.num = num;
? ? ? ? this.brand = brand;
? ? ? ? this.rent = rent;
? ? }

? ? //無參構(gòu)造
? ? public Vehicle() {
? ? }

? ? //get,set方法
? ? public String getNum() {
? ? ? ? return num;
? ? }

? ? public void setNum(String num) {
? ? ? ? this.num = num;
? ? }

? ? public String getBrand() {
? ? ? ? return brand;
? ? }

? ? public void setBrand(String brand) {
? ? ? ? this.brand = brand;
? ? }

? ? public double getRent() {
? ? ? ? return rent;
? ? }

? ? public void setRent(double rent) {
? ? ? ? this.rent = rent;
? ? }
}

子類Cars

public class Cars extends Vehicle{
? ? private String type;

? ? //重寫父類equals方法
? ? @Override
? ? public boolean equals(Vehicle v) {
? ? ? ? if(v instanceof Cars){
? ? ? ? ? ? Cars c=(Cars) v;
? ? ? ? ? ? return this.getBrand().equals(c.getBrand())&&this.getType().equals(c.getType());
? ? ? ? }
? ? ? ? return false;
? ? }

? ? //重寫父類費用方法
? ? @Override
? ? public double cost(int days,double sent) {
? ? ? ? if (days>150){
? ? ? ? ? ? return days*sent*0.7;
? ? ? ? }else if (days>30){
? ? ? ? ? ? return days*sent*0.8;
? ? ? ? }else if (days>7){
? ? ? ? ? ? return days*sent*0.9;
? ? ? ? }else {
? ? ? ? ? ? return days*sent;
? ? ? ? }
? ? }

? ? //無參構(gòu)造
? ? public Cars() {
? ? }

? ? //有參構(gòu)造
? ? public Cars(String num, String brand, double rent, String type) {
? ? ? ? super(num, brand, rent);
? ? ? ? this.type = type;
? ? }

? ? //2個有參構(gòu)造的方法
? ? public Cars(String brand,String type){
? ? ? ? super.setBrand(brand);
? ? ? ? this.type = type;
? ? }

? ? public String getType() {
? ? ? ? return type;
? ? }

? ? public void setType(String type) {
? ? ? ? this.type = type;
? ? }
}

子類Bus

public class Bus extends Vehicle{
? ? private int seat;

? ? //重寫父類的equals方法
? ? @Override
? ? public boolean equals(Vehicle v) {
? ? ? ? if(v instanceof Bus){
? ? ? ? ? ? Bus b=(Bus) v;
? ? ? ? ? ? return this.getBrand().equals(b.getBrand())&&this.getSeat()==b.getSeat();
? ? ? ? }
? ? ? ? return false;
? ? }

? ? //重寫父類費用方法
? ? @Override
? ? public double cost(int days,double rent) {
? ? ? ? if (days>=150){
? ? ? ? ? ? return days*rent*0.6;
? ? ? ? }else if (days>=30){
? ? ? ? ? ? return days*rent*0.7;
? ? ? ? }else if (days>=7){
? ? ? ? ? ? return days*rent*0.8;
? ? ? ? }else if (days>=3){
? ? ? ? ? ? return days*rent*0.9;
? ? ? ? }else {
? ? ? ? ? ? return days*rent;
? ? ? ? }
? ? }

? ? //2個參數(shù)的有參構(gòu)造
? ? public Bus(String brand,int seat){
? ? ? ? super.setBrand(brand);
? ? ? ? this.seat=seat;
? ? }

? ? //子類有參構(gòu)造
? ? public Bus(String num, String brand, double rent, int seat) {
? ? ? ? super(num, brand, rent);
? ? ? ? this.seat = seat;
? ? }

? ? //子類無參構(gòu)造
? ? public Bus(){}

? ? //子類get set 方法
? ? public int getSeat() {
? ? ? ? return seat;
? ? }

? ? public void setSeat(int seat) {
? ? ? ? this.seat = seat;
? ? }
}

汽車業(yè)務(wù)類VehicleServicer

public class VehicleServicer {

? ? public static List initVehicle(){
? ? ? ? Vehicle v1=new Bus("京6566754","金杯",800,16);
? ? ? ? Vehicle v2=new Bus("京9696996","金杯",1500,34);
? ? ? ? Vehicle v3=new Bus("京8696997","金龍",800,16);
? ? ? ? Vehicle v4=new Bus("京8696998","金龍",1500,34);
? ? ? ? Vehicle c1 =new Cars("京NT37465","別克",300,"林蔭大道");
? ? ? ? Vehicle c2 =new Cars("京9696996","別克",600,"GLB");
? ? ? ? Vehicle c3 =new Cars("京8696997","寶馬",800,"X6");
? ? ? ? Vehicle c4 =new Cars("京8696998","寶馬",600,"550i");

? ? ? ? //先裝入數(shù)組中
? ? ? ? Vehicle[] ve = {v1,v2,v3,v4,c1,c2,c3,c4};

? ? ? ? //將數(shù)組轉(zhuǎn)換成集合
? ? ? ? List<Vehicle> vehicles = Arrays.asList(ve);
? ? ? ? return vehicles;
? ? }


}

測試類Test

public class Test {
? ? public static void main(String[] args) {
? ? ? ? Scanner sc = new Scanner(System.in);
? ? ? ? System.out.println("**********歡迎光臨秋明山守望者汽車租賃公司**********");
? ? ? ? System.out.println("1.轎車 ? ?2.客車");
? ? ? ? System.out.print("請選擇你要租賃的汽車類型:");
? ? ? ? int type = sc.nextInt();
? ? ? ? //橋車
? ? ? ? Vehicle ve;
? ? ? ? String brand;
? ? ? ? if(type==1){
? ? ? ? ? ? System.out.print("請選擇你要租賃的汽車品牌(1.別克 ?2.寶馬):");
? ? ? ? ? ? int pinpai = sc.nextInt();
? ? ? ? ? ? String model=pinpai==1?"別克":"寶馬";
? ? ? ? ? ? if(pinpai==1){
? ? ? ? ? ? ? ? System.out.print("請輸入你要租賃的汽車類型(1.X6 ?2.550i):");
? ? ? ? ? ? ? ? int leixin = sc.nextInt();
? ? ? ? ? ? ? ? brand=leixin==1?"林蔭大道":"GL8";
? ? ? ? ? ? }else {
? ? ? ? ? ? ? ? System.out.print("請輸入你要租賃的汽車類型(1.X6 ?2.550i):");
? ? ? ? ? ? ? ? int leixin = sc.nextInt();
? ? ? ? ? ? ? ? brand=leixin==1?"X6":"550i";
? ? ? ? ? ? }
? ? ? ? ? ? ?ve = new Cars(model, brand);

? ? ? ? }else {//客車
? ? ? ? ? ? int seat;
? ? ? ? ? ? System.out.print("請選擇你要租賃的汽車品牌(1.金龍 ?2.金杯):");
? ? ? ? ? ? int pinpai = sc.nextInt();
? ? ? ? ? ? String s=pinpai==1?"金龍":"金杯";
? ? ? ? ? ? System.out.print("請選擇你要租賃的汽車座位數(shù)(1.16座 2.34座):");
? ? ? ? ? ? int z = sc.nextInt();
? ? ? ? ? ? seat =z==1?16:34;
? ? ? ? ? ? ve = new Bus(s, seat);
? ? ? ? }
? ? ? ? //根據(jù)選好的車型,輸出車牌和總價
? ? ? ? List<Vehicle> list = VehicleServicer.initVehicle();
? ? ? ? for (Vehicle v:list) {
? ? ? ? ? ? if(ve.equals(v)){
? ? ? ? ? ? ? ? System.out.print("請輸入你要租賃的天數(shù):");
? ? ? ? ? ? ? ? int days = sc.nextInt();
? ? ? ? ? ? ? ? System.out.println("分配給您的汽車牌號是:"+v.getNum());
? ? ? ? ? ? ? ? System.out.println("您需要支付的租賃費用是:"+v.cost(days,v.getRent()));
? ? ? ? ? ? }
? ? ? ? }

? ? }
}

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

相關(guān)文章

  • 關(guān)于Spring中一級緩存、二級緩存和三級緩存的那些事

    關(guān)于Spring中一級緩存、二級緩存和三級緩存的那些事

    Spring解決循環(huán)依賴的核心思想在于提前曝,下面這篇文章主要給大家介紹了關(guān)于Spring中一級緩存、二級緩存和三級緩存的那些事,文中通過實例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-02-02
  • 詳解Java爬蟲利器Jsoup

    詳解Java爬蟲利器Jsoup

    Jsoup是一款Java語言開發(fā)的HTML解析器,用于解析HTML文檔以及對HTML文檔進行操作,處理等,本文就將詳細(xì)給大家介紹一下Java中的爬蟲利器Jsoup,感興趣的同學(xué)可以參考一下
    2023-06-06
  • 阿里云發(fā)布 Spring Boot 新腳手架工程

    阿里云發(fā)布 Spring Boot 新腳手架工程

    這篇文章主要介紹了阿里云發(fā)布 Spring Boot 新腳手架的相關(guān)資料,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,可以參考下
    2020-04-04
  • Java發(fā)送http請求的示例(get與post方法請求)

    Java發(fā)送http請求的示例(get與post方法請求)

    這篇文章主要介紹了Java發(fā)送http請求的示例(get與post方法請求),幫助大家更好的理解和使用Java,感興趣的朋友可以了解下
    2021-01-01
  • 利用SpringBoot和LiteFlow解鎖復(fù)雜流程

    利用SpringBoot和LiteFlow解鎖復(fù)雜流程

    隨著業(yè)務(wù)的復(fù)雜化,企業(yè)需要更加高效、便捷地管理自己的業(yè)務(wù)流程,這就需要借助一些流程引擎實現(xiàn),今天,我們就來介紹一種基于Java語言開發(fā)的輕量級工作流引擎——LiteFlow,以及如何在Spring Boot框架中集成它,從而提高企業(yè)的工作效率和開發(fā)效率
    2023-06-06
  • Spring Boot Web 靜態(tài)文件緩存處理的方法

    Spring Boot Web 靜態(tài)文件緩存處理的方法

    本篇文章主要介紹了Spring Boot Web 靜態(tài)文件緩存處理的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-02-02
  • java設(shè)計模式系列之裝飾者模式

    java設(shè)計模式系列之裝飾者模式

    這篇文章主要為大家詳細(xì)介紹了java設(shè)計模式之裝飾者模式,裝飾者模式是一種結(jié)構(gòu)式模式,感興趣的朋友可以參考一下
    2016-02-02
  • 使用Java實現(xiàn)2048小游戲代碼實例

    使用Java實現(xiàn)2048小游戲代碼實例

    這篇文章主要介紹了使用Java實現(xiàn)2048小游戲代碼實例,2048 游戲是一款益智類游戲,玩家需要通過合并相同數(shù)字的方塊,不斷合成更大的數(shù)字,最終達(dá)到2048,游戲規(guī)則簡單,但挑戰(zhàn)性很高,需要玩家靈活運用策略和計算能力,本文將使用Java代碼實現(xiàn),需要的朋友可以參考下
    2023-10-10
  • Spring?Retry重試框架的使用講解

    Spring?Retry重試框架的使用講解

    重試的使用場景比較多,比如調(diào)用遠(yuǎn)程服務(wù)時,由于網(wǎng)絡(luò)或者服務(wù)端響應(yīng)慢導(dǎo)致調(diào)用超時,此時可以多重試幾次。用定時任務(wù)也可以實現(xiàn)重試的效果,但比較麻煩,用Spring?Retry的話一個注解搞定所有,感興趣的可以了解一下
    2022-10-10
  • IDEA2022 提示更新 TKK失敗請檢查網(wǎng)絡(luò)連接的問題

    IDEA2022 提示更新 TKK失敗請檢查網(wǎng)絡(luò)連接的問題

    這篇文章主要介紹了IDEA2022 提示:更新 TKK 失敗,請檢查網(wǎng)絡(luò)連接,本文給大家分享解決方案,對idea2022提示更新TKK失敗感興趣的朋友跟隨小編一起看看吧
    2022-11-11

最新評論