汽车租赁系统采用Java语言编写
----------------------------------------------------------------该代码亲试有效,欢迎各位dalao对代码不足处,提出建议,留言评论。
----------------------------------------------------------------本人QQ:2149810847
主要实现功能
1. 客户租两种不同的车,轿车和客车
2. 根据日租金和天数计算租金
3. 租赁多量车时计算总金额
主要方法
1. 抽象出汽车类,有子类为轿车类和客车类
2. 抽象方法为计算租金函数,和展示汽车基本信息函数
3. 轿车类有车名,皮牌,车牌号,车的数量,日租金等属性
4. 客车类有车名,皮牌,车牌号,车的数量,日租金,座位数等属性
5. 系统服务类,客户类。
6. 系统服务类有客户名单,轿车对象数组,客车对象数组,
7. 客户有登陆系统的root,password
package car_rental;
import java.io.*;
import java.util.*;
abstract class Car{
protected String carName; //车的名字
protected String carLabel; //品牌
protected String carNumber; //车牌号
protected int number_of_car; //车的数量
abstract double getRentPrice(int day);
abstract void displayInfo();
}
class Small_car extends Car{
private double dayRent;
//static int number_of_car = 0;
Small_car()
{}
Small_car(String carName, int dayRent, String carLabel, String carNumber, int number_of_car){
this.carName = carName;//
this.dayRent = dayRent;
this.carLabel = carLabel;
this.carNumber = carNumber;
this.number_of_car = number_of_car;
}
void displayInfo() {
System.out.println(this.carName + " " + this.carLabel + " " + this.carNumber + " "
+ this.dayRent + " " + this.number_of_car);
}
double getRentPrice(int day){
return this.dayRent * day;
}
}
class Passenger_car extends Car{
private int carSeat;
private double dayRent1;
private double dayRent2;
Passenger_car()
{}
Passenger_car(String carName, double dayRent1, double dayRent2, String carLabel, String carNumber,int carSeat, int number_of_car){
this.carName = carName;//
this.dayRent1 = dayRent1;
this.dayRent2 = dayRent2;
this.carLabel = carLabel;
this.carNumber = carNumber;
this.carSeat = carSeat;
this.number_of_car = number_of_car;
}
void displayInfo() {
System.out.print(this.carName + " " + this.carLabel + " " + this.carNumber + " "
+ this.carSeat + " " + this.number_of_car + " ");
if (this.carSeat > 16)
System.out.println(this.dayRent2);
else
System.out.println(this.dayRent1);
}
@Override
double getRentPrice(int day){
if (this.carSeat > 16)
return this.dayRent2 * day;
else
return this.dayRent1 * day;
}
}
class Car_client{
String clientName;
String password;
double price;
static double allPrice = 0.0;
Car_client(){}
void setName(String clientName) {
this.clientName = clientName;
}
void setPassword(String password) {
this.password = password;
}
char chooseServe(char flag) {
if (flag == '0')
System.out.println("clientName = " + this.clientName + "\tALL price = " + this.allPrice);
return flag;
}
int chooseCar() {
Scanner sc =new Scanner(System.in);
int number = sc.nextInt();
return number;
}
int chooseDay() {
Scanner sc =new Scanner(System.in);
int day = sc.nextInt();
return day;
}
}
class Car_serve_system{
Small_car sCar[];
Passenger_car pCar[];
Car_client client;
void Serve(char flag) {
if (flag == '0')
this.exitSystem();
if (flag == '1')
this.display_scar();
if (flag == '2')
this.display_pcar();
}
void login() {
System.out.println("欢迎登录汽车租赁系统");
}
void mainWindow() {
System.out.println(" *****欢迎进入汽车租赁系统***** ");
}
void initCar() {
sCar = new Small_car[10];
pCar = new Passenger_car[3];
sCar[0] = new Small_car("本田CRV", 600, "宝马", "京NY28588", 2);
sCar[1] = new Small_car("福特", 500, "宝马", "京1234567", 3);
sCar[2] = new Small_car("本田HRV", 400, "宝马", "京1000000", 3);
sCar[3] = new Small_car("本田CRV", 600, "别克", "京NT43765", 4);
sCar[4] = new Small_car("福特", 500, "别克", "京2000000", 5);
sCar[5] = new Small_car("本田HRV", 400, "别克", "京3000000", 6);
sCar[6] = new Small_car("本田CRV", 600, "金龙", "京5643765", 0);
sCar[7] = new Small_car("福特", 500, "金龙", "京N565656", 9);
sCar[8] = new Small_car("本田HRV", 400, "金龙", "京7777777", 10);
sCar[9] = new Small_car("本田CRV", 600, "宝马", "京NNN3284", 2);
pCar[0] = new Passenger_car("<=16座", 800, 1000, "ZK6535DX", "京123", 15, 15);
pCar[1] = new Passenger_car(">16座", 800, 1000, "ZK6809DX", "京123", 25, 2);
pCar[2] = new Passenger_car(">16座", 800, 1000, "T7(V6)汽油版", "京123", 40, 5);
}
void display_scar() {
System.out.println("车的名字" + " " + "车的品牌" + " " + "车牌号" + " "
+ "日租费" +" "+ "可租的数量");
for (Small_car sc : sCar){
sc.displayInfo();
}
System.out.print("请选择第几辆车租借:");
}
void display_pcar() {
System.out.println("车的名字" + " " + "车的品牌" + " " + "车牌号" + " "
+ "车座数" + " " + "可租的数量" + " " + "日租费");
for (Passenger_car pc : pCar) {
pc.displayInfo();
}
System.out.print("请选择第几辆车租借:");
}
void exitSystem() {
System.exit(0); //
}
void give_s_car(int flag) {
if (sCar[flag-1].number_of_car > 0) {
System.out.print("请选择租借天数:");
this.client.price = this.sCar[flag-1].getRentPrice(this.client.chooseDay());
this.sCar[flag-1].number_of_car--;
System.out.println("price = " + this.client.price);
this.client.allPrice += this.client.price;
}
else {
System.out.print("该车已经全部被出租!请另外选择!");
this.give_s_car(this.client.chooseCar());
}
}
void give_p_car(int flag) {
if (pCar[flag-1].number_of_car > 0) {
System.out.print("请选择租借天数:");
this.client.price = this.pCar[flag-1].getRentPrice(this.client.chooseDay());
this.pCar[flag-1].number_of_car--;
System.out.println("price = " + this.client.price);
this.client.allPrice += this.client.price;
}
else {
System.out.print("该车已经全部被出租!请另外选择!");
this.give_s_car(this.client.chooseCar());
}
}
}
public class Rent_car{
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
Scanner sc =new Scanner(System.in); //raed
Car_serve_system carSystem = new Car_serve_system();
Car_client carClient = new Car_client();
carSystem.client = carClient;
carSystem.login();
System.out.print("please write your name:");
carClient.setName(sc.nextLine());
System.out.print("please write your password:");
carClient.setPassword(sc.nextLine());
carSystem.initCar();
carSystem.mainWindow();
char flag = 'a';
while (flag != '0') { //while true :
System.out.println(" 0:退出" + " " +"1:租轿车" + " " + "2:租客车 ");
flag = (char)System.in.read();
carSystem.Serve(carClient.chooseServe(flag));
if (flag == '1') {
carSystem.give_s_car(carClient.chooseCar());
}
else
carSystem.give_p_car(carClient.chooseCar());
}
}
}