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

java編寫(xiě)汽車(chē)租賃系統(tǒng)

 更新時(shí)間:2022年02月24日 11:19:53   作者:??悲宸???  
這篇文章主要為大家詳細(xì)介紹了java編寫(xiě)汽車(chē)租賃系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

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

題目要求:

1,汽車(chē)租賃信息表如下:

2,類(lèi)和屬性:

3,運(yùn)行效果:

效果實(shí)現(xiàn):

代碼實(shí)現(xiàn):

1,車(chē)類(lèi):

package homework.exam;

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

? ? 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;
? ? }

? ? public Vehicle() {
? ? }
? ? //含參構(gòu)造
? ? public Vehicle(String num, String brand, double rent) {
? ? ? ? this.num = num;
? ? ? ? this.brand = brand;
? ? ? ? this.rent = rent;
? ? }

? ? @Override
? ? public String toString() {
? ? ? ? return "汽車(chē){" +
? ? ? ? ? ? ? ? "車(chē)牌號(hào)='" + num + '\'' +
? ? ? ? ? ? ? ? ", 品牌='" + brand + '\'' +
? ? ? ? ? ? ? ? ", 日租金=" + rent +
? ? ? ? ? ? ? ? '}';
? ? }
? ? public abstract double totalmoney(int days , double rent);
? ? public abstract boolean equals(Vehicle o);
}

2,汽車(chē)類(lèi):

package homework.exam;

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


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

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

? ? public Cars(String brand,String type) {
? ? ? ? this.type = type;

? ? }

? ? public Cars(String num, String brand, double rent, String type) {
? ? ? ? super(num, brand, rent);
? ? ? ? this.type = type;
? ? }

? ? @Override
? ? public String toString() {
? ? ? ? return "Cars{" +
? ? ? ? ? ? ? ? "type='" + type + '\'' +
? ? ? ? ? ? ? ? '}';
? ? }

? ? //計(jì)算小汽車(chē)的總租金
? ? @Override
? ? public double totalmoney(int days, double rent) {
? ? ? ? if (days>7){
? ? ? ? ? ? return days*rent*0.9;
? ? ? ? }else if (days>30){
? ? ? ? ? ? return days*rent*0.8;
? ? ? ? }else if (days>150){
? ? ? ? ? ? return days*rent*0.7;
? ? ? ? }
? ? ? ? return days*rent;
? ? }
? ? //重寫(xiě)equals方法
? ? @Override
? ? public boolean equals(Vehicle o) {
? ? ? ? if (o instanceof Cars){
? ? ? ? ? ? Cars cars= (Cars) o;
? ? ? ? ? ? return this.getType().equals(cars.getType())&&this.getBrand().equals(o.getBrand());
? ? ? ? }
? ? ? ? return false;
? ? }
}

3,客車(chē)類(lèi):

package homework.exam;

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

? ? public String getSeat() {
? ? ? ? return seat;
? ? }

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

? ? public Bus(String num, String brand, double rent, String seat) {
? ? ? ? super(num, brand, rent);
? ? ? ? this.seat = seat;
? ? }

? ? //計(jì)算客車(chē)的租金
? ? @Override
? ? public double totalmoney(int days, double rent) {
? ? ? ? if (days>=3){
? ? ? ? ? ? return days*rent*0.9;
? ? ? ? }else if (days>=7){
? ? ? ? ? ? return days*rent*0.8;
? ? ? ? }else if (days>=30){
? ? ? ? ? ? return days*rent*0.7;
? ? ? ? }else if (days>=150){
? ? ? ? ? ? return days*rent*0.6;
? ? ? ? }
? ? ? ? return days*rent;
? ? }
? ? //重寫(xiě)equals方法
? ? @Override
? ? public boolean equals(Vehicle o) {
? ? ? ? return false;
? ? }
}

4,車(chē)輛管理類(lèi):

package homework.exam;

public class CarRent {
? ? //創(chuàng)建汽車(chē)數(shù)組,將汽車(chē)的信息放在數(shù)組中
? ? public Cars[] carMake(){
? ? ? ? Cars c1 = new Cars("京NY28588", "寶馬", 800, "x6");
? ? ? ? Cars c2 = new Cars("京CNY3284", "寶馬", 600, "550i");
? ? ? ? Cars c3 = new Cars("京NT37465", "別克", 300, "林蔭大道");
? ? ? ? Cars c4 = new Cars("京NT96928", "別克", 600, "GL8");
? ? ? ? Cars[] arr1 ={c1,c2,c3,c4};
? ? ? ? return arr1;
? ? }
? ? //創(chuàng)建客車(chē)數(shù)組,將汽車(chē)的信息放在數(shù)組中
? ? public Bus[] busMake(){
? ? ? ? Bus b1 = new Bus("京6566754", "金杯", 800, "16座");
? ? ? ? Bus b2 = new Bus("京8696667", "金龍", 800, "16座");
? ? ? ? Bus b3 = new Bus("京9696996", "金杯", 1500, "34座");
? ? ? ? Bus b4 = new Bus("京8696998", "金龍", 1500, "34座");
? ? ? ? Bus[] arr2={b1,b2,b3,b4};
? ? ? ? return arr2;
? ? }
}

5,業(yè)務(wù)服務(wù)類(lèi):

package homework.exam;

import java.util.Scanner;

public class CarService {
? ? public void rentcar(){
? ? ? ? System.out.println("**********歡迎光臨秋名山守望者汽車(chē)租賃公司**********");
? ? ? ? Scanner sc = new Scanner(System.in);
? ? ? ? System.out.println("1,轎車(chē) ?2,客車(chē)");
? ? ? ? System.out.print("請(qǐng)輸入您要租賃的汽車(chē)類(lèi)型:");
? ? ? ? int i = sc.nextInt();
? ? ? ? CarRent carRent = new CarRent(); ? ?//創(chuàng)建車(chē)庫(kù)對(duì)象
? ? ? ? Cars[] cars = carRent.carMake(); ? ?//拿到轎車(chē)數(shù)組對(duì)象
? ? ? ? Cars car=null;
? ? ? ? Bus[] buses = carRent.busMake(); ? ?//拿到客車(chē)數(shù)組對(duì)象
? ? ? ? Bus bus=null;
? ? ? ? //判斷用戶選擇的車(chē)型
? ? ? ? if (i==1){
? ? ? ? ? ? System.out.print("請(qǐng)選擇你要租賃的汽車(chē)品牌:(1,別克 ?2,寶馬)");
? ? ? ? ? ? int i1 = sc.nextInt();
? ? ? ? ? ? if (i1==1){
? ? ? ? ? ? ? ? System.out.print("請(qǐng)輸入你要租賃的汽車(chē)類(lèi)型:(1,林蔭大道 2,GL8 )");
? ? ? ? ? ? }else {
? ? ? ? ? ? ? ? System.out.print("請(qǐng)輸入你要租賃的汽車(chē)類(lèi)型:(1,x6 2,550i )");
? ? ? ? ? ? }
? ? ? ? ? ? String i2 = sc.next();
? ? ? ? ? ? //遍歷汽車(chē)數(shù)組,拿到用戶選擇的汽車(chē)
? ? ? ? ? ? for (int j = 0; j < cars.length; j++) {
? ? ? ? ? ? ? ? if (cars[j].getType().equals(i2)){ ?//當(dāng)選擇的車(chē)的類(lèi)型與數(shù)組中的匹配時(shí)
? ? ? ? ? ? ? ? ? ? car=cars[j]; ? ? ? ?//將車(chē)賦值給car
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? System.out.print("請(qǐng)輸入你要租賃的天數(shù):");
? ? ? ? ? ? int days = sc.nextInt();
? ? ? ? ? ? System.out.print("分配給你的汽車(chē)牌號(hào)是:");
? ? ? ? ? ? System.out.println(car.getNum()); ? //獲取汽車(chē)的車(chē)牌
? ? ? ? ? ? double totalmoney =0; ? ? ? ? ? //調(diào)用total
? ? ? ? ? ? totalmoney = car.totalmoney(days, car.getRent()); ? //計(jì)算用戶的租金
? ? ? ? ? ? System.out.print("你需要支付的租賃分費(fèi)用是:");
? ? ? ? ? ? System.out.print(totalmoney);

? ? ? ? }else if (i==2){
? ? ? ? ? ? System.out.print("請(qǐng)選擇你要租賃的汽車(chē)品牌:(1,金龍 ?2,金杯)");
? ? ? ? ? ? String i2 = sc.next();
? ? ? ? ? ? System.out.print("請(qǐng)輸入你要租賃的汽車(chē)座位數(shù):(1,16座 ?2,34座)");
? ? ? ? ? ? String i3 = sc.next();
? ? ? ? ? ? //遍歷客車(chē)數(shù)組,拿到用戶選擇的客車(chē)
? ? ? ? ? ? for (int j = 0; j < buses.length; j++) {
? ? ? ? ? ? ? ? //當(dāng)輸入的客車(chē)的車(chē)牌和座位與數(shù)組中的相等,就選出用戶選擇的車(chē)
? ? ? ? ? ? ? ? if (buses[j].getBrand().equals(i2)&&buses[j].getSeat().equals(i3)){
? ? ? ? ? ? ? ? ? ? bus=buses[j]; ? //將選擇的車(chē)輛賦值給bus
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? System.out.print("請(qǐng)輸入你要租賃的天數(shù):");
? ? ? ? ? ? int days = sc.nextInt();
? ? ? ? ? ? System.out.print("分配給你的汽車(chē)牌號(hào)是:");
? ? ? ? ? ? System.out.println();
? ? ? ? ? ? System.out.println(bus.getNum()); ? //拿到用戶選擇的車(chē)牌號(hào)
? ? ? ? ? ? double totalmoney = 0; ? ? ?//調(diào)用totalmoney方法
? ? ? ? ? ? totalmoney=bus.totalmoney(days, bus.getRent()); ? ? //用用戶輸入的天數(shù)。來(lái)計(jì)算租金
? ? ? ? ? ? System.out.print("你需要支付的租賃分費(fèi)用是:");
? ? ? ? ? ? System.out.print(totalmoney);
? ? ? ? }
? ? }
}

6,測(cè)試類(lèi):

package homework.exam;

public class Test {
? ? public static void main(String[] args) {
? ? ? ? CarService cs = new CarService();
? ? ? ? cs.rentcar();
? ? }
}

控制臺(tái)輸入的內(nèi)容,我選擇的是輸入字符串類(lèi)型,沒(méi)有按照效果圖上,如果你做的話,你可以用三元運(yùn)算符來(lái)實(shí)現(xiàn)哦!

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

相關(guān)文章

  • java 字符串轉(zhuǎn)化為字符數(shù)組的3種實(shí)現(xiàn)案例

    java 字符串轉(zhuǎn)化為字符數(shù)組的3種實(shí)現(xiàn)案例

    這篇文章主要介紹了java 字符串轉(zhuǎn)化為字符數(shù)組的3種實(shí)現(xiàn)案例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-10-10
  • Java設(shè)計(jì)模式之Adapter適配器模式

    Java設(shè)計(jì)模式之Adapter適配器模式

    這篇文章主要為大家詳細(xì)介紹了Java設(shè)計(jì)模式之Adapter適配器模式,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-03-03
  • SpringAop源碼及調(diào)用過(guò)程概述

    SpringAop源碼及調(diào)用過(guò)程概述

    這篇文章主要介紹了SpringAop源碼及調(diào)用過(guò)程概述,Spring AOP(面向切面編程)是Spring框架的一個(gè)重要特性,它提供了一種在程序運(yùn)行期間動(dòng)態(tài)地將額外的行為織入到代碼中的方式,需要的朋友可以參考下
    2023-10-10
  • IDEA中的Kafka管理神器詳解

    IDEA中的Kafka管理神器詳解

    這款基于IDEA插件實(shí)現(xiàn)的Kafka管理工具,能夠在本地IDE環(huán)境中直接運(yùn)行,簡(jiǎn)化了設(shè)置流程,為開(kāi)發(fā)者提供了更加緊密集成、高效且直觀的Kafka操作體驗(yàn)
    2025-01-01
  • 說(shuō)一說(shuō)java關(guān)鍵字final和transient

    說(shuō)一說(shuō)java關(guān)鍵字final和transient

    這篇文章主要和大家說(shuō)一說(shuō)java關(guān)鍵字final和transient,感興趣的小伙伴們可以參考一下
    2016-06-06
  • IDEA使用Mybatis插件 MyBatisCodeHelper-Pro的圖文教程

    IDEA使用Mybatis插件 MyBatisCodeHelper-Pro的圖文教程

    這篇文章主要介紹了IDEA使用Mybatis插件 MyBatisCodeHelper-Pro的教程,本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-09-09
  • Java 信息摘要加密MD2、MD4、MD5實(shí)現(xiàn)詳解

    Java 信息摘要加密MD2、MD4、MD5實(shí)現(xiàn)詳解

    這篇文章主要介紹了Java 信息摘要加密MD2、MD4、MD5實(shí)現(xiàn)詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-07-07
  • Java中的復(fù)合數(shù)據(jù)類(lèi)型

    Java中的復(fù)合數(shù)據(jù)類(lèi)型

    這篇文章主要介紹了Java中的復(fù)合數(shù)據(jù)類(lèi)型,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-10-10
  • Java虛擬機(jī)GC日志分析

    Java虛擬機(jī)GC日志分析

    這篇文章主要介紹了Java虛擬機(jī)GC日志分析,分享了相關(guān)代碼示例,小編覺(jué)得還是挺不錯(cuò)的,具有一定借鑒價(jià)值,需要的朋友可以參考下
    2018-02-02
  • Java如何實(shí)現(xiàn)實(shí)體類(lèi)轉(zhuǎn)Map、Map轉(zhuǎn)實(shí)體類(lèi)

    Java如何實(shí)現(xiàn)實(shí)體類(lèi)轉(zhuǎn)Map、Map轉(zhuǎn)實(shí)體類(lèi)

    這篇文章主要介紹了Java 實(shí)現(xiàn)實(shí)體類(lèi)轉(zhuǎn)Map、Map轉(zhuǎn)實(shí)體類(lèi)的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-08-08

最新評(píng)論

太康县| 专栏| 海林市| 林西县| 遂宁市| 绥宁县| 内丘县| 玛沁县| 原平市| 贵定县| 浮梁县| 乃东县| 富锦市| 莱阳市| 桂平市| 克拉玛依市| 龙口市| 桓台县| 恩平市| 南投县| 东阳市| 邵阳县| 东台市| 汉川市| 辽阳县| 中西区| 梧州市| 周至县| 宝鸡市| 广德县| 兴安盟| 宁明县| 潮安县| 湘阴县| 盐山县| 义乌市| 罗定市| 舟曲县| 宝丰县| 福建省| 临邑县|