汽车租赁系统的简单实现
来源:互联网 发布:手机淘宝旺旺号是什么 编辑:程序博客网 时间:2024/05/01 16:06
java基础,简单实现汽车租赁功能,适合初学者。实现选车 租车 租赁天数 计算价格功能。
public abstract class MotoVehicle {
private String no;
private String brand;
private String color;
private int mileage;
public MotoVehicle(){}
public MotoVehicle(String no, String brand, String color, int mileage) {
super();
this.no = no;
this.brand = brand;
this.color = color;
this.mileage = mileage;
}
abstract int ClacRent(/*int days*/);
public String getNo() {
return no;
}
public void setNo(String no) {
this.no = no;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public int getMileage() {
return mileage;
}
public void setMileage(int mileage) throws Exception {
if(mileage<0){
mileage = 10;
throw new Exception("里程必须大于0");
}
this.mileage = mileage;
}
}
Bus类
public class Bus extends MotoVehicle {
private int seatCount;
public Bus(String no, String brand, String color, int mileage, int seatCount) {
super(no,brand,color,mileage);
this.seatCount = seatCount;
}
public int getSeatCount() {
return seatCount;
}
public void setSeatCount(int seatCount) {
this.seatCount = seatCount;
}
@Override
int ClacRent(/*int days*/) {
int rent = 0;
if (getSeatCount() <= 16) {
rent = 800;
} else {
rent = 1500;
}
return rent;
}
}
Car类
public class Car extends MotoVehicle {
private String type;
public Car(String no, String brand, String color, int mileage, String type) {
super(no,brand,color,mileage);
this.type = type;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@Override
int ClacRent(/*int days*/) {
int rent = 0;
if ("别克商务GL8".equals(getType())) {
rent = 600;
} else if ("宝马550i".equals(getType())) {
rent = 500;
} else if ("别克林荫大道".equals(getType())) {
rent = 300;
}
return rent;
}
}
Main方法:有数据初始化,还有租车模块的实现。
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
//初始化
Car[] c = new Car[3];
Bus[] b = new Bus[4];
c[0] = new Car("粤A10001", "别克", "黑", 0, "别克商务GL8");
c[1] = new Car("粤A10002", "宝马", "蓝", 0, "宝马550i");
c[2] = new Car("粤A10003", "别克", "红", 0, "别克林荫大道");
b[0] = new Bus("粤A10004", "金杯", "黄", 0, 16);
b[1] = new Bus("粤A10005", "金杯", "金", 0, 34);
b[2] = new Bus("粤A10006", "金龙", "白", 0, 16);
b[3] = new Bus("粤A10007", "金龙", "银", 0, 34);
System.out.println("----欢迎租车----\n");
for(int i = 0; i<c.length; i++) {
System.out.println("序号:"+(i+1)+", 品牌:"+c[i].getBrand()
+", 车型:"+c[i].getType()+", 租金:"+c[i].ClacRent(/*i*/));
}
for(int i = 0; i<b.length; i++) {
System.out.println("序号:"+(i+4)+", 品牌:"+b[i].getBrand()+", 座位数:"+b[i].getSeatCount()+", 租金:"+b[i].ClacRent(/*i*/));
}
//租车模块
byte[] byts = new byte[1024];
int k = 0;
int num = 0;
int d = 0;
//int sum1 = 0;int sum2 = 0;int sum3 = 0;int sum4 = 0;int sum5 = 0; int sum6 = 0; int sum7 =0;
int sum[] = {0,0,0,0,0,0,0};
int sumRent = 0;
Scanner sc = new Scanner(System.in);
while (true) {
try {
System.out.println("\n\n是否需要租车(0-是,其他键退出):");
int n = System.in.read(byts);
String s = new String(byts, 0, n);
if (s.trim().length() == 0) {
continue;
}
int input = Integer.parseInt(s.trim()); // 强制转换为需要的类型
if (input != 0) {
System.out.println("退出!");
return;
}
do{
System.out.print("请选择您需要的车型(选序号):");
n = System.in.read(byts);
s = new String(byts,0,n);
int key = Integer.parseInt(s.trim());
switch(key) {
case 1:
System.out.print("您选择的是"+c[0].getType()+"\n请输入租赁数量:");
num = sc.nextInt();
System.out.print("请输入租赁天数:");
d = sc.nextInt() * c[0].ClacRent(/*0*/);
sum[0] = num * d;
System.out.print("价格为:"+sum[0] );
break;
case 2:
System.out.print("您选择的是"+c[1].getType()+"\n请输入租赁数量:");
num = sc.nextInt();
System.out.print("请输入租赁天数:");
d = sc.nextInt() * c[1].ClacRent(/*0*/);
sum[1] = num * d;
System.out.print("价格为:"+sum[1] );
break;
case 3:
System.out.print("您选择的是"+c[2].getType()+"\n请输入租赁数量:");
num = sc.nextInt();
System.out.print("请输入租赁天数:");
d = sc.nextInt() * c[2].ClacRent(/*0*/);
sum[2] = num * d;
System.out.println("价格为:"+sum[2] );
break;
case 4:
case 5:
case 6:
case 7:
System.out.println("暂时没有此类车型!");
break;
default:
System.out.println("输入有误!");
break;
}
System.out.println("\n如果还有租赁需求请按0,按任意键提交订单!");
k = sc.nextInt();
}while(k == 0);
sumRent = sum[0]+sum[1]+sum[2];
System.out.println("请您支付"+sumRent+"元,凭票出门右转提车,欢迎再次光临!");
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
这就是简单的汽车租赁系统,希望对初学者有帮助。有问题的朋友可以留言!
日后有时间我会更新如何用SSM框架实现一些简单的项目,如博客平台,管理系统等。
0 0
- 汽车租赁系统的简单实现
- 实现汽车租赁系统的计价功能
- 基于SSM的汽车租赁系统
- 汽车租赁管理系统
- 汽车租赁系统
- 汽车租赁系统
- 汽车租赁系统
- 汽车租赁管理系统
- 汽车租赁系统
- 汽车租赁系统
- 汽车租赁系统
- 汽车租赁系统项目
- (系统)基于封装/抽象/多态的简单的汽车租赁系统
- 继承、多态:汽车租赁系统
- java汽车租赁系统代码
- 汽车租赁公司CIS数据库系统的设计
- 金石汽车租赁管理系统 下载
- 汽车租赁管理系统-期末项目
- Javascript(一)
- puppet概述
- Volley源码解析(一)——发送请求与结束请求
- Xlua热补丁原理
- ES6模块的import和export用法总结
- 汽车租赁系统的简单实现
- 谈谈高并发系统的限流
- 小波去噪DWT
- MFC 导航界面
- 10 个超酷的 HTML5/CSS3 应用及源码
- MATLAB GUI编程入门
- 分享10 个超酷的 HTML5/CSS3 应用及源码
- 分享10款功能强大的HTML5/CSS3应用插件
- 7款外观迷人的HTML5/CSS3 3D按钮特效