汽车租赁系统

package test;

import java.util.Scanner;

public class Test
{
    public static void main(String[] args)
    {
        // 用户输入需要租车的类型和天数
        // 系统返回总价格

        Scanner input = new Scanner(System.in);

        System.out.println("----欢迎来到协同汽车租赁公司-----");
        System.out.println("请选择车辆类型:1.轿车 2.客车");

        int autoType = input.nextInt();

        if (autoType == 1)
        {
            Car car = new Car();
            System.out.println("请选择轿车的品牌:1.宝马  2.别克");
            int brand = input.nextInt();
            car.setBrand(brand);
            if (brand == 1)
            {
                System.out.println("请选择宝马的类型:1.X6  2.550i");
            } else
            {
                System.out.println("请选择别克的类型:1.林荫大道  2.GL8");
            }
            int type = input.nextInt();
            car.setType(type);
            car.setRentPrice();
            System.out.println("请输入您需要租的天数:");
            int days = input.nextInt();
            RentCompany rc = new RentCompany();
            rc.pay(car, days);
        }
        if (autoType == 2)
        {
            Bus bus = new Bus();
            System.out.println("请选择轿车的品牌:1.金龍  2.金杯");
            int brand = input.nextInt();
            bus.setBrand(brand);
            if (brand == 1)
            {
                System.out.println("请选择金龍的类型:1.16座  2.34座");
            } else
            {
                System.out.println("请选择金杯的类型:1.16座  2.34座");
            }
            int type = input.nextInt();
            bus.setType(type);
            bus.setRentPrice();
            System.out.println("请输入您需要租的天数:");
            int days = input.nextInt();
            RentCompany rc = new RentCompany();

            rc.pay(bus, days);
        }

    }

}

package test;

public class Bus extends Auto
{
//    private int seatNumber;
//
//    public int getSeatNumber()
//    {
//        return seatNumber;
//    }
//
//    public void setSeatNumber(int seatNumber)
//    {
//        this.seatNumber = seatNumber;
//    }

    private String type;

    public String getType()
    {
        return type;
    }

    public void setType(int type)
    {
        if (getBrand().equals("金龍"))
        {
            if (type == 1)
            {
                this.type = "16座";
            } else
            {
                this.type = "34座";
            }
        } else
        {
            if (type == 1)
            {
                this.type = "16座";
            } else
            {
                this.type = "34座";
            }

        }
    }

    @Override
    public void setRentPrice()
    {
        if (getBrand().equals("金杯"))
        {
            if (this.getType().equals("16座"))
            {
                this.setPrice(800);
                this.setNo("京6566754");
            } else
            {
                this.setPrice(1500);
                this.setNo("京9696996");
            }

        } else
        {
            if (this.getType().equals("16座"))
            {
                this.setPrice(800);
                this.setNo("京8696997");
            } else
            {
                this.setPrice(1500);
                this.setNo("京8696998");
            }

        }

    }

}
 

package test;

public class Car extends Auto
{
    private String type;

    public String getType()
    {
        return type;
    }

    public void setType(int type)
    {
        if (getBrand().equals("宝马"))
        {
            if (type == 1)
            {
                this.type = "X6";
            } else
            {
                this.type = "550i";
            }
        } else
        {
            if (type == 1)
            {
                this.type = "林荫大道";
            } else
            {
                this.type = "GL8";
            }

        }
    }

    @Override
    public void setRentPrice()
    {
        if (getBrand().equals("宝马"))
        {
            if(this.getType().equals("X6"))
            {
                this.setPrice(800);
                this.setNo("京NY28588");
            }
            else
            {
                this.setPrice(600);
                this.setNo("京CNY3284");
            }

        } else
        {
            if(this.getType().equals("林荫大道"))
            {
                this.setPrice(300);
                this.setNo("京NT37465");
            }
            else
            {
                this.setPrice(600);
                this.setNo("京NT96968");
            }

        }

    }

}
 

 

package test;

public class RentCompany
{
    public void pay(Auto auto, int days)
    {

        int sum = auto.getPrice() * days;//租金*天数

        if (auto instanceof Car)//通过判断输入的车型判断是否属于Car类
        {
            if (days > 0)
            {

                if (days > 7 && days <= 30)
                {
                    sum = (int) (sum * 0.9);
                } else if (days > 30 && days <= 150)
                {
                    sum = (int) (sum * 0.8);
                } else if (days > 150)
                {
                    sum = (int) (sum * 0.7);
                }

            }

            String brand = auto.getBrand();//品牌
            String type = ((Car) auto).getType();//型号
            if (auto instanceof Car)

                System.out.println("您选择了" + brand + type + ",车牌为"
                        + auto.getNo() + ",日租金为" + auto.getPrice()
                        + ",优惠后您需要支付" + sum + "元");
        } else
        {
            if (days > 0)
            {

                if (days >= 3 && days < 7)
                {
                    sum = (int) (sum * 0.9);
                } else if (days >= 7 && days < 30)
                {
                    sum = (int) (sum * 0.8);
                } else if (days >= 30 && days < 150)
                {
                    sum = (int) (sum * 0.7);
                } else if (days >= 150)
                {
                    sum = (int) (sum * 0.6);
                }

            }

            String brand = auto.getBrand();
            String type = ((Bus) auto).getType();

            System.out.println("您选择了" + brand + type + ",车牌为" + auto.getNo()
                    + ",日租金为" + auto.getPrice() + ",优惠后您需要支付" + sum + "元");
        }

    }

}
 

 

package test;

import java.util.Scanner;

public class Test
{
    public static void main(String[] args)
    {
        // 用户输入需要租车的类型和天数
        // 系统返回总价格

        Scanner input = new Scanner(System.in);

        System.out.println("----欢迎来到协同汽车租赁公司-----");
        System.out.println("请选择车辆类型:1.轿车 2.客车");

        int autoType = input.nextInt();

        if (autoType == 1)
        {
            Car car = new Car();
            System.out.println("请选择轿车的品牌:1.宝马  2.别克");
            int brand = input.nextInt();
            car.setBrand(brand);
            if (brand == 1)
            {
                System.out.println("请选择宝马的类型:1.X6  2.550i");
            } else
            {
                System.out.println("请选择别克的类型:1.林荫大道  2.GL8");
            }
            int type = input.nextInt();
            car.setType(type);
            car.setRentPrice();
            System.out.println("请输入您需要租的天数:");
            int days = input.nextInt();
            RentCompany rc = new RentCompany();
            rc.pay(car, days);
        }
        if (autoType == 2)
        {
            Bus bus = new Bus();
            System.out.println("请选择轿车的品牌:1.金龍  2.金杯");
            int brand = input.nextInt();
            bus.setBrand(brand);
            if (brand == 1)
            {
                System.out.println("请选择金龍的类型:1.16座  2.34座");
            } else
            {
                System.out.println("请选择金杯的类型:1.16座  2.34座");
            }
            int type = input.nextInt();
            bus.setType(type);
            bus.setRentPrice();
            System.out.println("请输入您需要租的天数:");
            int days = input.nextInt();
            RentCompany rc = new RentCompany();

            rc.pay(bus, days);
        }

    }

}
 

  • 4
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值