简单的租车系统

//Car父类

package com.carsystem;
public class Car{
/**
* 定义车的编号,名称以及租金
**/
private int id;
private String name;
private int rents;
// 封装
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getValue() {
return rents;
}
public void setValue(int rents) {
this.rents = rents;
}
}

//LoadGoods载货接口

public interface LoadGoods {
int weight=0;
public int getILoad();
public void setILoad(int weight);
}

//注:接口中所有的方法都是抽象方法,接口中只可以定义,不可以实现

//LoadPassengers载人接口

public interface LoadPassengers {
int number=0;
public int getIPassage();
public void setIPassage(int number);
}

//载人车类

package com.carsystem;


public class PassengersCar extends Car implements LoadPassengers {
PassengersCar(int id,String name,int rents,int number){
this.setId(id);
this.setName(name);
this.setValue(rents);
this.setIPassage(number);
}
private int number;
@Override
public String toString() {
return " "+ getId()+" "+ getName() + " " + getValue()+" " + getIPassage() + " ";
}
@Override
public int getIPassage() {
// TODO Auto-generated method stub
return number;
}
@Override
public void setIPassage(int number) {
// TODO Auto-generated method stub
         this.number=number;
}

}

//载货车类

package com.carsystem;


public class Truck extends Car implements LoadGoods {
@Override
public String toString() {
return " "+ getId()+" "+ getName() + " " + getValue()+" " + getILoad();
}
Truck(int id,String name,int rents,int weight){
this.setId(id);
this.setName(name);
this.setValue(rents);
this.setILoad(weight);
}
private int weight;
@Override
public int getILoad() {
// TODO Auto-generated method stub
return weight;
}


@Override
public void setILoad(int weight) {
// TODO Auto-generated method stub
        this.weight=weight;
}

}

//既可载人也可载货车类

package com.carsystem;


public class PickUp extends Car implements LoadGoods, LoadPassengers {
PickUp(int id,String name,int rents,int number,int weight) {
this.setId(id);
this.setName(name);
this.setValue(rents);
this.setIPassage(number);
this.setILoad(weight);
}
private int number;
private int weight;
@Override
public String toString() {
return " "+ getId()+" "+ getName() + " " + getValue()+" " + getIPassage() + " "+ getILoad();
}
       @Override
public int getIPassage() {
// TODO Auto-generated method stub
return number;
}
@Override
public void setIPassage(int number) {
// TODO Auto-generated method stub
this.number=number;
}
@Override
public int getILoad() {
// TODO Auto-generated method stub
return weight;
}
@Override
public void setILoad(int weight) {
// TODO Auto-generated method stub
this.weight=weight;
}

}

//测试类

package com.carsystem;


import java.util.*;


public class Text {
public static void main(String[] args) {
/*********
* 租车系统功能如下: 
* 1.显示所有可租车辆
* 2.用户选择车型、租车数量 
* 3.展示租车清单,包含总金额、车型及总载货量以及总载人数
**********/
// TODO Auto-generated method stub
System.out.println("欢迎来到租车系统:");
Car[] cars = { new PassengersCar(0, "奥迪A4", 500, 4),
new PassengersCar(1, "马自达6", 400, 4),
new PickUp(2, "皮卡雪6", 450, 4, 2),
new PickUp(3, "金龙", 800, 2, 10), 
new Truck(4, "松花江", 400, 4),
new Truck(5, "依维柯", 1000, 20) };
Scanner input = new Scanner(System.in);
System.out.println("请问您是否要租车?  1:是     2:不是");
int choice = input.nextInt();
if (choice == 1) {
System.out.println("欢迎进入租车系统,以下为您可租选的车辆及其价目表:");
System.out.println("序号 汽车名称  租金(元/天)  容量");
//输出价目表要记得重写tostring方法
for (int i = 0; i < cars.length; i++) {
System.out.println(cars[i]);
}
System.out.println("以下即为您的租车信息:");
System.out.println("请输入您想要租车的数量:");
int val=input.nextInt();//输入租车数量 
System.out.println("请输入序号0~5");
Car[] cars1=new Car[val]; 
int[] days=new int[val]; 
for(int i=0;i<val;i++){
System.out.println("请选择第"+(i+1)+"辆车的序号:"); 
int inputValue=input.nextInt();
cars1[i]=cars[inputValue];
//租车的类型 
System.out.println(cars1[i].getName()); 
System.out.println("请选择借出天数");
days[i]=input.nextInt(); 
}
System.out.println("您的租赁清单:");
int[] totalPrice=new int[val]; 
int sum=0; 
for(int i=0;i<val;i++){ 
totalPrice[i]=days[i]*cars[i].getValue(); 
System.out.println(cars1[i].getName()+"\t"+"借出天数:"+days[i]+"\t"+"总计:"+totalPrice[i]);
}
for(int i=0;i<val;i++)
sum+=totalPrice[i]; 
System.out.println("总价格:"+sum); 
        input.close();
}
else {
System.out.println("关闭此页即可..");
  }
}
}

一个简单汽车租赁管理系统C++控制台程序): 利用C++实现汽车和客户信息的增、删、改等操作,并保存。 部分代码: // CarRent.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include "CarData.h" #include "Menu.h" #include"CustomerData.h" int main() { Menu::welcome(); Menu::login(); //登录界面 char choice; int carid, customerid; //汽车编号,客户编号 CustomerData CustomerDB; //客户库 Customer *r; //客户 CarData CarDB; //汽车库 Car *b; //汽车 Menu::showMenu(); //显示菜单 cout <> choice; while (choice != '0') { switch (choice) { case '1': //输入客户编号和要出租的汽车 cout <> customerid; try { if (customerid <= 0) throw 1; } catch (...) { cout << "输入有误,请重新输入"; break; } cout <> carid; try { if (carid <= 0) throw 1; } catch (...) { cout << "输入有误,请重新输入"; break; } r = CustomerDB.search(customerid); if (NULL == r) { cout << "不存在该客户!"; cout << endl; break; } b = CarDB.search(carid); if (b == NULL) { cout << "不存在该汽车!"; cout <borrowCar() == 0) { cout << "该汽车已租出!"; cout <borrowCar(b->getNo()); cout << "你在" <getBorTime()) << "成功出租一辆" <getName() << endl << "每日租金为(不足一天按一天计算):" <getPay(); break; case '2': //归还操作 cout <> customerid; try { if (customerid <= 0) throw 1; } catch (...) { cout << "输入有误,请重新输入"; break; } cout <> carid; try { if (carid <= 0) throw 1; } catch (...) { cout << "输入有误,请重新输入"; break; } r = CustomerDB.search(customerid); //按编号查找 if (r == NULL) { cout << "不存在该客户!" << endl; break; } b = CarDB.search(carid); if (b == NULL) { cout << "不存在该汽车!" <getOnshelf() == 1) { cout << "该汽车已经归还!" << endl; break; } cout << "您成功归还一辆"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值