当前位置: 首页 > article >正文

汽车租赁系统1.0版本

汽车租赁系统1.0版本比较简陋,以后还会有2.0、3.0……就像《我爱发明》里面的一代机器二代机器,三代机器一样,是一个迭代更新的过程(最近比较忙,可能会很久),这个1.0版本很简陋,也请大家提提意见。

 

下面是代码区:

首先是文件Car.java

package Car;

public class Car {
    String brand;
    String type;
    String vehicleid;
    int rent;

    public Car() {
        // 默认构造函数
    }

    public Car(String tempbrand, String temptype, String tempvehicleid, int temprent) {
        brand = tempbrand;
        type = temptype;
        vehicleid = tempvehicleid;
        rent = temprent;
    }

    public double getTotalRent(int tempday) {
        if (tempday <= 7)
            return tempday * rent;
        else if (tempday > 7 && tempday <= 30)
            return tempday * rent * 0.9;
        else if (tempday > 30 && tempday <= 150)
            return tempday * rent * 0.8;
        else
            return tempday * rent * 0.7;
    }
}

然后是 文件Main.java

 我简单弄了个while循环,如果你输入了系统里面没有的型号或者输错了,它会一直提醒你重新输入,直到你正确输入,然后输入租车天数才会退出。

package Car;

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        // 数组初始化
        Car[] cars = new Car[4]; // 假设我们需要四个元素
        cars[0] = new Car("长安", "X", "京CNY3284", 800);
        cars[1] = new Car("长安", "Y", "京NY28588", 300);
        cars[2] = new Car("吉利", "G", "京NT37465",300);
        cars[3] = new Car("吉利", "H", "京NT96968",500);
        // 示例:计算一个车的总租金
        System.out.println("请输入你想租车的型号");
        Scanner sc = new Scanner(System.in);
        while (true){
        String type = sc.next();
        int index=-1;
        for(int i=0;i<cars.length;i++) {
            if(cars[i].type.equals(type))
                index = i;
        }
        if(index<0) {
            System.out.println("对不起,没有您想要的型号");
            System.out.println("请重新输入:");
        }
        else{
                System.out.println("请输入你想租车的天数:");
                int days = sc.nextInt();
                System.out.println("该型号租金单价" + cars[index].rent + "元/天");
                double totalRent = cars[index].getTotalRent(days);
                System.out.println("您共需支付租金:" + totalRent + "元");
                break;
            }
        }
    }
}


http://www.kler.cn/news/304508.html

相关文章:

  • Linux——进程状态
  • 【React Native】第三方组件
  • 前端层面----监控与埋点
  • EasyExcel拿表头(二级表头)爬坑,invokeHeadMap方法
  • 记录一下,Vcenter清理/storage/archive空间
  • kafka 之 本地部署单机版
  • spring项目期间的学习9/11
  • 《论企业集成平台的技术与应用》写作框架,软考高级系统架构设计师
  • 数据库系统 第58节 数据库审计
  • 创意无限:五款AI绘画应用,让艺术创作更简单
  • Java基础 --- 多线程JUC,以及一些常用的设计模式总结
  • 前端form表单+ifarme方式实现大文件下载
  • OpenAI 刚刚推出 o1 大模型!!突破LLM极限
  • 医疗行业怎么节约和管理能源
  • Leetcode 每日一题:Longest Increasing Path in a Matrix
  • Python安装:Mac 使用brew 安装Python2 和 Python3
  • 古文字定位系统源码分享
  • [项目实战]EOS多节点部署
  • 深入解析 org.apache.maven.plugins
  • 解锁 macOS 剪贴板历史记录,高效复制、粘贴技巧
  • Python 爬虫入门 - 爬虫 requests 请求
  • 内存区域-面试与分析
  • IP网络广播服务平台upload接口存在任意文件上传漏洞
  • Java中等题-移掉k位数字(力扣)
  • Go websocket
  • Python基础学习(1)
  • overleaf如何下载论文的pdf
  • 使用PyTorch进行图像风格迁移:基于VGG19实现
  • Git工作流程
  • Nacos 与 Eureka 的区别