汽车租赁系统V1.0

这篇博客记录了一位Java初学者实现汽车租赁系统V1.0的过程,包括Car类和RentMgrSys类的设计。作者注意到vehicleId属性在当前版本未使用,车牌号显示可能与预期不符,且leaseOutFlow()方法未实际应用。博客提到在V2.0中会有所改进,并对自己的代码进行了简单评价。
摘要由CSDN通过智能技术生成

汽车租赁系统V1.0

首先是做题要求

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

以下是代码和思路

我用的是idea,需创建一个Car类和一个RentMgrSys类
代码如下
Car类

package cars;

public class Car {
    private String vehicleId;
    private String brand;
    private String type;
    private int perRent;

    public Car() {
    }

    public Car(String vehicleId, String brand, String type, int perRent) {
        this.vehicleId = vehicleId;
        this.brand = brand;
        this.type = type;
        this.perRent = perRent;
    }

    public String getVehicleId() {
        return vehicleId;
    }

    public void setVehicleId(String vehicleId) {
        this.vehicleId = vehicleId;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public int getPerRent() {
        return perRent;
    }

    public void setPerRent(int perRent) {
        this.perRent = perRent;
    }

    public float calRent(int days){
        float money;
        if(days > 150) {
            money = getPerRent() * days * 7 / 10;
        }else if(days > 30){
            money = getPerRent() * days * 8 / 10;
        }else if(days >7) {
            money = getPerRent() * days * 9 / 10;
        }else
            money = getPerRent() * days;
        return money;
    }

    public void leaseOutFlow(){

    }
}

RentMgrSys类

package cars;

import java.util.Scanner;

public class RentMgrSys {
    public static void main(String[] args) {
        Car car;
        String vehicleId, type, brand;
        int days;
        Scanner sc = new Scanner(System.in);
        System.out.print("请选择你要租赁的汽车类型:");
        vehicleId = sc.next();
        System.out.println("1.宝马     2.别克");
        System.out.print("请选择你要租赁的轿车品牌:");
        brand = sc.next();
        if("1".equals(brand)){
            System.out.println("1.550i   2.X6");
            System.out.print("请选择你要租赁的轿车型号:");
            type = sc.next();
            if("1".equals(type)){
                System.out.print("请输入您要租赁的天数:");
                days = sc.nextInt();
                System.out.println("分配给您的汽车牌号是: 京CNY3284");
                car = new Car(vehicleId, brand, type, 600);
                System.out.print("您需要支付的租赁费用是:"+
                        car.calRent(days)+"元");
            }
            else if("2".equals(type)){
                System.out.print("请输入您要租赁的天数:");
                days = sc.nextInt();
                System.out.println("分配给您的汽车牌号是: 京NY28588");
                car = new Car(vehicleId, brand, type, 800);
                System.out.print("您需要支付的租赁费用是:"+
                        car.calRent(days)+"元");
            }
        }
        else if("2".equals(brand)){
            System.out.println("1.林荫大道   2.GL8");
            System.out.print("请选择你要租赁的轿车品牌:");
            type = sc.next();
            if("1".equals(type)){
                System.out.print("请输入您要租赁的天数:");
                days = sc.nextInt();
                System.out.println("分配给您的汽车牌号是: 京NT37465");
                car = new Car(vehicleId, brand, type, 300);
                System.out.print("您需要支付的租赁费用是:"+
                        car.calRent(days)+"元。s");

            }
            else if("2".equals(type)){
                System.out.print("请输入您要租赁的天数:");
                days = sc.nextInt();
                System.out.println("分配给您的汽车牌号是:  京NT96968 ");
                car = new Car(vehicleId, brand, type, 600);
                System.out.print("您需要支付的租赁费用是:"+
                        car.calRent(days)+"元");
            }
        }
    }
}

我的运行结果为
在这里插入图片描述
在这里插入图片描述
这上面应该还有选项,由于是V1.0,老师直接截取了下面一部分,
V2.0题目如下
在这里插入图片描述

遇到的一些问题

1、 所以说,本题中的属性vehicleId基本没有用,只是为了V2.0做准备。

2、 我的运行结果车牌号与参考界面给出的不同,但是我觉得,根据输入的1,1,2, 2对应的是宝马X6,车牌号是京NY28588。(可能是老师出题比较随意,也可能是我理解错了)

3、 题目要求的leaseOutFlow()方法 //租车流程,我并没有用,流程都写在RentMgrSys类中的main方法中了。

总结

作为Java小白,代码水平有限,不够精简,只是做简单的分享,更多的是记录日常。

  • 5
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值