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

汽车租赁系统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;elsereturn 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.mrgr.cn/news/27151.html

相关文章:

  • 【四】k8s部署 TDengine集群
  • TCP套接字【网络】
  • 2-94 基于matlab的最佳维纳滤波器的盲解卷积算法
  • 《论网络安全体系设计》写作框架,软考高级系统架构设计师
  • xmake vscode+clangd实现c/c++程序更精确跳转、补全
  • 小琳AI课堂:o1系列模型
  • Python 中的高并发 I/O
  • 什么是幂等
  • Coggle数据科学 | 科大讯飞AI大赛:人岗匹配挑战赛 赛季3
  • Java多线程编程-基础篇
  • 利士策分享,细品礼仪之美:在日常中优雅相处的艺术
  • 【FATFS】FATFS简介及下载
  • ​经​纬​恒​润​二​面​​三​七​互​娱​一​面​​元​象​二​面​
  • ET 框架问题集合(请收藏,不定时更新)
  • 【例题】lanqiao1331 二进制中 1 的个数
  • MySQL聚合统计
  • Nginx:Web架构中的全能战士
  • 一分钟教你 全平台隔空投送文件 LoaclSend保姆级教程
  • Git换行符自动转换参数core.autocrlf的用法
  • 【零成本】七日杀 服务器搭建 异地联机 无需公网IP、服务器