汽车租赁系统

13 篇文章 0 订阅

一:汽车类

  public abstract  class Vehicle
    {
      public Vehicle() { }
      public Vehicle(string licenseNO,string name,string color,int yearOfService,double dailyRent)
      {
          this.licenseNO = licenseNO;
          this.name = name;
          this.color = color;
          this.yearOfService = yearOfService;a
          this.dailyRent = dailyRent;
      }
      //租用日期
        private int rentDate;

        public int RentDate
        {
            get { return rentDate; }
            set { rentDate = value; }
        }
      //租用者
        private string rentUser;

        public string RentUser
        {
            get { return rentUser; }
            set { rentUser = value; }
        }
      //日租金
        private double dailyRent;

        public double DailyRent
        {
            get { return dailyRent; }
            set { dailyRent = value; }
        }
      //使用时间
        private int yearOfService;

        public int YearOfService
        {
            get { return yearOfService; }
            set { yearOfService = value; }
        }
      //颜色
        private string color;

        public string Color
        {
            get { return color; }
            set { color = value; }
        }
      //车名
        private string name;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }
      //车牌号
        private string licenseNO;

        public string LicenseNO
        {
            get { return licenseNO; }
            set { licenseNO = value; }
        }
      //计算价格的方法
        public abstract double CalcPrice();
    }


二:轿车类

public class Car:Vehicle
    {
       public Car(string licenseNO, string name, string color, int yearsOfService, double dailyRent)
           : base(licenseNO, name, color, yearsOfService, dailyRent)
       {
           ;
       }
       public override double CalcPrice()
       {
           double totalPrice = 0;
           double basicPrice = this.RentDate * this.DailyRent;
           if (this.RentDate <= 30)
           {
               totalPrice = basicPrice;
           }
           else
           {
               totalPrice = basicPrice + (this.RentDate - 30) * this.DailyRent * 0.1;
           }
           return totalPrice;
       }
    }


三:卡车类

public class Truck:Vehicle
    {
       public Truck() { }
       public Truck(string licenseNO, string name, string color, int yearsOfService, double dailyRent, int load)
           : base(licenseNO, name, color, yearsOfService, dailyRent)
       {
           this.Load = load;
       }
       //载重量
        private int load;

        public int Load
        {
            get { return load; }
            set { load = value; }
        }
       //卡车费用计算方法
        // 30天以内(含30)按日租金计算
        // 30天以上超出部分:每天,每吨(载重量)增加日租金10%
        public override double CalcPrice()
        {
            double totalPrice = 0;
            double basicPrice = RentDate * DailyRent;
            if (RentDate<=30)
            {
                totalPrice = basicPrice;
            }
            else
            {
                totalPrice = basicPrice + (RentDate - 30) * (DailyRent * 0.1)*load;
            }
            return totalPrice;
        }
    }


四:汽车类型"工厂"
public class VehicleFactory
    {
       public static Vehicle CreateVehicle(string licenseNO,string name,string color,int yearOfService,double dailyRent,int load,string type)
       {
           Vehicle vehicle = null;
           switch (type)
           {
               case "car":
                   vehicle = new Car(licenseNO, name, color, yearOfService, dailyRent);
                   break;
               case "truck":
                   vehicle = new Truck(licenseNO,name,color,yearOfService,dailyRent,load);
                   break;
               default:
                   break;
           }
           return vehicle;
       }
    }

五:在主窗体加载汽车信息

 public partial class Rent : Form
    {
        public Rent()
        {
            InitializeComponent();
        }
        //保存可租用车的集合(车辆名称,车辆对象)
        Dictionary<string, Vehicle> notRent;
        //保存已租用车辆的集合。
        Dictionary<string, Vehicle> alreadyRent;
        private void btnQueryRent_Click(object sender, EventArgs e)
        {
            //刷新
            MyRefresh(notRent, lvRent);
        }
        //构造出两辆小汽车,两辆卡车
        public void LoadData()
        {
            //实例化未出租字典类型的集合
            notRent = new Dictionary<string, Vehicle>();
            Car car = new Car("京R00544", "奥迪A8", "黑色", 3, 240);
            Truck truck = new Truck("京R44944", "东风", "蓝色", 3, 300, 20);
            notRent.Add(car.LicenseNO,car);
            notRent.Add(truck.LicenseNO,truck);

            //实例化已出租字典类型的集合
            alreadyRent = new Dictionary<string, Vehicle>();
            //出租出去的车
            Car rentCar = new Car("粤A001", "宝马318", "白色", 3, 250);
            rentCar.RentUser = txtRenter.Text;
            Truck rentTruck = new Truck("粤A002", "东风", "蓝色", 3, 400, 30);
           
            alreadyRent.Add(rentCar.LicenseNO, rentCar);
            alreadyRent.Add(rentTruck.LicenseNO,rentTruck);
        }


六:绑定TreeView,刷新显示

 public void MyRefresh(Dictionary<string,Vehicle> rnotrent, ListView lvshow)
        {
            lvshow.Items.Clear();
            foreach (Vehicle item in rnotrent.Values)
            {
                ListViewItem lvitem = new ListViewItem(item.LicenseNO);
                if (item is Car)
                {
                    lvitem.SubItems.Add(item.Name);
                    lvitem.SubItems.Add(item.Color);
                    lvitem.SubItems.Add(item.YearOfService.ToString());
                    lvitem.SubItems.Add(item.DailyRent.ToString());
                }
                if (item is Truck)
                {
                    lvitem.SubItems.Add(item.Name);
                    lvitem.SubItems.Add(item.Color);
                    lvitem.SubItems.Add(item.YearOfService.ToString());
                    lvitem.SubItems.Add(item.DailyRent.ToString());
                    lvitem.SubItems.Add(((Truck)item).Load.ToString());
                }
                lvshow.Items.Add(lvitem);
            }
        }

 //刷新
        private void btnQueryReturn_Click(object sender, EventArgs e)
        {
            MyRefresh(alreadyRent,lvReturn);
        }

七:租车

 private void btnRent_Click(object sender, EventArgs e)
        {
            if (txtRenter.Text=="")
            {
                MessageBox.Show("请输入租车人名称");
                return;
            }
            //从可租车辆集合中移除车辆A
            //将A添加到已租车辆集合中
            if (lvRent.SelectedItems.Count>0)
            {
                string number = lvRent.SelectedItems[0].Text;
                Vehicle ve = notRent[number];
                notRent.Remove(number);
                MyRefresh(notRent,lvRent);
                alreadyRent.Add(number, ve);
                MessageBox.Show("租车成功!");
            }
           
        }

八:还车界面的结算

 private void btnCompute_Click(object sender, EventArgs e)
        {
            if (txtRentDate.Text=="")
            {
                MessageBox.Show("请输入租车时间");
                return;
            }
            //01.将车A从已租集合中移除   //02,将车A加入到可租车辆中
            string number=lvReturn.SelectedItems[0].Text;
            Vehicle ve = alreadyRent[number];
            alreadyRent.Remove(number);
            MyRefresh(alreadyRent, lvReturn);
            notRent.Add(number, ve);
            ve.RentDate = Convert.ToInt32(txtRentDate.Text);
            double money=0;
           
            money = ve.CalcPrice();
            MessageBox.Show("您需要支付"+money+"元");

        }

九:新车入库的添加

private void btnAdd_Click(object sender, EventArgs e)
        {
            string lincesN0=txtAutoNum.Text;
            string name=txtName.Text;
            string color=cobColor.Text;
            int time=Convert.ToInt32(txtYears.Text);
            double dailyRent=Convert.ToInt32(txtLetting.Text);
           
            if (rdoCar.Checked)
            {
                
                Car car = new Car(lincesN0, name, color, time, dailyRent);
                notRent.Add(lincesN0, car);
            }
            if (rdoTruck.Checked)
            {
                int load = Convert.ToInt32(txtLoad.Text);
                Truck truck = new Truck(lincesN0, name, color, time, dailyRent, load);
                notRent.Add(lincesN0, truck);
            }
            MessageBox.Show("添加成功!");
        }

十:轿车和卡车的按钮

 private void rdoCar_CheckedChanged(object sender, EventArgs e)
        {
            txtLoad.Enabled = false;
        }

        private void rdoTruck_CheckedChanged(object sender, EventArgs e)
        {
            txtLoad.Enabled = true;
        }



  • 4
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
一、项目简介本课程演示的是一套基于SSM实现汽车租赁系统,主要针对计算机相关专业的正在做毕设的学生与需要项目实战练习的Java学习者。课程包含: 1. 项目源码、项目文档、数据库脚本、软件工具等所有资料2. 带你从零开始部署运行本套系统3. 该项目附带的源码资料可作为毕设使用4. 提供技术答疑和远程协助指导二、技术实现 后台框架:Spring、SpringMVC、MyBatisUI界面:jQuery 、JSP数据库:MySQL 三、系统功能系统分为前台用户租车和后台系统管理:    1.前台用户租车        用户注册、用户登录、用户中心、浏览车辆、车辆搜索        查看车辆明细、租赁车辆、我的订单    2.后台系统管理        用户管理:用户列表、添加用户、修改用户、删除用户、查询用户        新闻管理:新闻列表、添加新闻、修改新闻、删除新闻、查询新闻        车辆品牌管理:车辆品牌列表、添加车辆品牌、修改车辆品牌、删除车辆品牌        车辆管理:车辆列表、添加车辆、修改车辆、删除车辆、查询车辆        订单管理:订单列表、确认订单、删除订单        报表管理:统计信息查询和展示 四、项目截图1)前台用户界面 2)后台系统管理    更多Java毕设项目请关注【毕设系列课程】https://edu.csdn.net/lecturer/2104   点击 我的百科 ,通过百度百科更多了解我 ^_^ 

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值