java实现简单汽车租赁系统

 更新时间:2021年01月20日 09:31:00   作者:小苏(º﹃º )  
这篇文章主要为大家详细介绍了java实现简单汽车租赁系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了java实现汽车租赁系统的具体代码,供大家参考,具体内容如下

一、使用技术

javaSE

二、实现功能

汽车租赁系统

具体要求如下:

使用面向对象的知识实现一个汽车租赁系统

1.汽车租赁信息表如下

2.类和属性

三、运行效果图


1.先创建一个汽车类作为父类,这里有汽车的公共属性:

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.创建一个轿车类,继承汽车类的属性

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.创建一个客车类,继承汽车类的属性

public class Passengercar extends Automobile{//客车
private String seatingCapacity;//座位数

  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.创建测试类,用于实现这个系统

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("请选择你要租赁的天数");
            double a3=sc.nextInt();
            System.out.println("分配给您的汽车牌号是:"+c2.getLicensePlate());
            System.out.print("您需要支付的租赁费用是:");
            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("请选择你要租赁的天数");
            double a3=sc.nextInt();
            System.out.println("分配给您的汽车牌号是:"+c1.getLicensePlate());
            System.out.print("您需要支付的租赁费用是:");
            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("请选择你要租赁的天数");
            double a3=sc.nextInt();
            System.out.println("分配给您的汽车牌号是:"+c4.getLicensePlate());
            System.out.print("您需要支付的租赁费用是:");
            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("请选择你要租赁的天数");
            double a3=sc.nextInt();
            System.out.println("分配给您的汽车牌号是:"+c3.getLicensePlate());
            System.out.print("您需要支付的租赁费用是:");
            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("请选择你要租赁的汽车座位数:1、16座 2、34座");
          String a2=sc.next();
          if (a2.equals("1")){//16座
            System.out.println("请选择你要租赁的天数");
            double a3=sc.nextInt();
            System.out.println("分配给您的汽车牌号是:"+p2.getLicensePlate());
            System.out.print("您需要支付的租赁费用是:");
            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("请选择你要租赁的天数");
            double a3=sc.nextInt();
            System.out.println("分配给您的汽车牌号是:"+p4.getLicensePlate());
            System.out.print("您需要支付的租赁费用是:");
            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("请选择你要租赁的汽车座位数:1、16座 2、34座");
          String a2=sc.next();
          if (a2.equals("1")){//16座
            System.out.println("请选择你要租赁的天数");
            double a3=sc.nextInt();
            System.out.println("分配给您的汽车牌号是:"+p1.getLicensePlate());
            System.out.print("您需要支付的租赁费用是:");
            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("请选择你要租赁的天数");
            double a3=sc.nextInt();
            System.out.println("分配给您的汽车牌号是:"+p3.getLicensePlate());
            System.out.print("您需要支付的租赁费用是:");
            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("是否还要继续选车 1继续 2终止");
      String x=sc.next();
      if (x.equals("2")){
        System.out.println("欢迎下次光临!");
        break;
      }
      System.out.println();
      System.out.println();
    }


  }

}

1.轿车的实现

2.客车的实现

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

  • 基于SpringBoot和Vue3的博客平台的用户注册与登录功能实现

    基于SpringBoot和Vue3的博客平台的用户注册与登录功能实现

    本教程将指导您如何使用Spring Boot和Vue3实现用户注册与登录功能。我们将使用Spring Boot作为后端框架,Vue3作为前端框架,同时使用MySQL作为数据库,感兴趣的朋友可以参考一下
    2023-04-04
  • Java实现动态数据源切换的实践指南

    Java实现动态数据源切换的实践指南

    在 Java 开发中,许多场景需要访问多个数据库,例如多租户系统或读写分离架构,为了灵活高效地管理这些场景,动态数据源切换技术应运而生,所以本文给大家介绍了Java实现动态数据源切换的实践指南,需要的朋友可以参考下
    2025-03-03
  • springboot对数据库密码加密的实现

    springboot对数据库密码加密的实现

    这篇文章主要介绍了springboot对数据库密码加密的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-12-12
  • Mybatis-plus动态条件查询QueryWrapper的使用案例

    Mybatis-plus动态条件查询QueryWrapper的使用案例

    mybatis-plus框架功能很强大,把很多功能都集成了,下面这篇文章主要给大家介绍了关于Mybatis-plus动态条件查询QueryWrapper的使用教程,文中通过图文介绍的非常详细,需要的朋友可以参考下
    2022-07-07
  • 一文详解Spring Security的基本用法

    一文详解Spring Security的基本用法

    Spring Security是一个功能强大且高度可定制的身份验证和访问控制框架, 提供了完善的认证机制和方法级的授权功能。本文将通过一个简单的案例了解一下Spring Security的基本用法,需要的可以参考一下
    2022-05-05
  • Java时间戳类Instant的使用详解

    Java时间戳类Instant的使用详解

    这篇文章主要为大家详细介绍了Java中时间戳类Instant的使用方法,文中的示例代码讲解详细,对我们学习Java有一定帮助,需要的可以参考一下
    2022-09-09
  • 浅析spring定时器的使用

    浅析spring定时器的使用

    这篇文章主要介绍了浅析spring定时器的使用,帮助大家更好的理解和学习spring框架,感兴趣的朋友可以了解下
    2020-10-10
  • java实现微信抢红包算法

    java实现微信抢红包算法

    这篇文章主要为大家详细介绍了java实现微信抢红包算法,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2020-09-09
  • Java中Easypoi实现excel多sheet表导入导出功能

    Java中Easypoi实现excel多sheet表导入导出功能

    这篇文章主要介绍了Java中Easypoi实现excel多sheet表导入导出功能,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2021-01-01
  • MyBatis中的占位符入参全面详解

    MyBatis中的占位符入参全面详解

    这篇文章主要为大家介绍了MyBatis中的占位符全面详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-03-03

最新评论