Java作业-租车小系统

项目介绍:

根据所学知识,编写一个控制台版的“答答租车系统”

功能:

  1. 展示所有可租车辆
  2. 选择车型、天数。
  3. 展示租车清单,包括:总金额、总载货量及其车型、总载入量及其车型。

欢迎使用答答租车系统

您是否租车?

1:是 2:否

下面是车辆类型和价格表

序号车名租金(天)容量
1奥迪A45004人
2马自达64004人
3皮卡雪4504人和2吨货
4金龙80020人
5松花江4004吨货
6依维柯100020吨货

下面是主要的代码.

代码展示


public class Choose {

    private Car car;

    public Choose() {
        System.out.println("以下是车辆可选菜单");
        System.out.println("1号车,奥迪A4,日租金500,可乘坐4人");
        System.out.println("2号车,马自达6,日租金400,可乘坐4人");
        System.out.println("3号车,皮卡雪,日租金450,可乘坐4人,且载货2吨");
        System.out.println("4号车,金龙,日租金800,可乘坐20人");
        System.out.println("5号车,松花江,日租金400,可乘坐4人");
        System.out.println("6号车,依维柯,日租金1000,可载货20吨");
        System.out.println("请输入你要选择的车辆序号");
        Scanner sc = new Scanner(System.in);
        int i = sc.nextInt();
        System.out.println("请输入租车的天数");
        int day = sc.nextInt();
        if (i < 7) {
            chooseCar(i, day);
            System.out.println("您的租车账单为:" + car.getName() + ",租期为" + car.getDay() + "天,总租金为" + car.getPrice() * day + ",可乘坐" + car.getMan() + "人,可装载" + car.getGoods() + "吨货");
            System.out.println("请支付"+car.getPrice() * day+"元!");
            System.out.println("欢迎下次光临!");
        }
    }

    public void chooseCar(int i, int day) {

        if (i==1) {
            this.car = new Car1(day);
        }
        if (i==2) {
            this.car = new Car2(day);
        }
        if (i==3){
            this.car = new Car3(day);
        }
        if(i==4){
            this.car = new Car4(day);
        }
        if(i==5){
            this.car = new Car5(day);
        }
        if(i==6){
            this.car = new Car6(day);
        }


    }
public class CarMain {
    public static void main(String[] args) {
        boolean result = hello();

        if (result){
            System.out.println("欢迎下次光临!");
            return;
        }

        new Choose();

    }


    public static boolean hello() {
        System.out.println("欢迎来到答答租车系统");
        System.out.println("你是否确定租车  1:确认  0:退出");
        Scanner sc = new Scanner(System.in);
        int ch = sc.nextInt();
        if (ch==1){
            return false;
        }else{
            return true;
        }
    }

}

Last modification:June 5, 2020
如果觉得我的文章对你有用,请随意赞赏