利用java实现简单租车系统(控制台程序版)

    //测试类
package com.System.show;

import com.leasesystem.car.*;
import java.util.Scanner;

public class Demo {
    public static void main(String[] args) {
        int sum = 0;
        int peopleSum = 0;
        int goodsSum = 0;

        System.out.println("您是否租车?(1:是/0:不是)");
        Scanner scanner = new Scanner(System.in);
        String  num1 = scanner.next();
        if ("1".equals(num1)) {
            System.out.println("序号"+" "+"类型"+" "+"价格"+" "+"容量");
            for(int i = 1;i<7;i++){
                Vehicle car = Demo.showCar(i);
                System.out.println(car.getId()+" "+car.getType()+" "+car.getPrice()+" "+car.getCapacity()+car.getCapaUnit());
            }
            for (boolean bool = true;bool == true;) {
                System.out.println("请输入要租的车型(0:选车结束):");
                String  num2 = scanner.next();
                int num2_1 = Integer.parseInt(num2);
                if("0".equals(num2)){
                    bool = false;
                }else if(num2_1 >6){
                    System.out.println("输入错误!重新输入");
                }else{
                    Vehicle car = Demo.showCar(num2_1);
                    sum += car.getPrice();
                    if (car.getCapaUnit().equals("吨/辆")) {
                        goodsSum += car.getCapacity();
                    }else{
                        peopleSum += car.getCapacity();
                    }
                }
            }
        } else {
            System.out.println("谢谢光临");
        }
        System.out.println("租借清单:");
        System.out.println("总金额:"+sum);
        System.out.println("总载人量:"+peopleSum);
        System.out.println("总载货量:"+goodsSum);
        scanner.close();
    }

    private static Vehicle showCar(int i) {
        switch (i) {
            case 1:
                {
                    Vehicle car = new SalooCar();
                    return car;
                }
            case 2:
            {
                Vehicle car = new StandardCar();
                return car;
            }
            case 3:
            {
                Vehicle car = new Bus();
                return car;
            }
            case 4:
            {
                Vehicle car = new Truck();
                return car;
            }
            case 5:
            {
                Vehicle car = new HeavyTruck();
                return car;
            }
            case 6:
            {
                Vehicle car = new Pickup();
                return car;
            }
            default:
            {
                Vehicle car = new StandardCar();
                return car;
            }
        }
    }
}

//抽象car父类
package com.leasesystem.car;

public abstract class Vehicle {
     int id;
     String type;
     int price;
     int capacity;
     String capaUnit;

    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public int getPrice() {
        return price;
    }
    public void setPrice(int price) {
        this.price = price;
    }
    public int getCapacity() {
        return capacity;
    }
    public void setCapacity(int capacity) {
        this.capacity = capacity;
    }
    public String getCapaUnit() {
        return capaUnit;
    }
    public void setCapaUnit(String capaUnit) {
        this.capaUnit = capaUnit;
    }
}

//各种类型的车类
//豪华轿车类
package com.leasesystem.car;

public class SalooCar extends Vehicle {
    public SalooCar(){
        this.id = 1;
        this.type = "豪华轿车";
        this.price = 500;
        this.capacity = 6;
        this.capaUnit = "人/辆";
    }
}

//普通汽车类
package com.leasesystem.car;

public class StandardCar extends Vehicle {
    public StandardCar() {
        this.id = 2;
        this.type = "普通汽车";
        this.price = 350;
        this.capacity = 4;
        this.capaUnit = "人/辆";
    }
}
//客车类
package com.leasesystem.car;

public class Bus extends Vehicle {
    public Bus(){
        this.id = 3;
        this.type = "客车";
        this.price = 1000;
        this.capacity = 50;
        this.capaUnit = "人/辆";
    }
}
//货车类
package com.leasesystem.car;

public class Truck extends Vehicle {
    public Truck() {
        this.id = 4;
        this.type = "卡车";
        this.price = 1000;
        this.capacity = 5;
        this.capaUnit = "吨/辆";
    }
}
//重型货车类
package com.leasesystem.car;

public class HeavyTruck extends Vehicle {
    public HeavyTruck() {
            this.id = 5;
            this.type = "重型货车";
            this.price = 3000;
            this.capacity = 20;
            this.capaUnit = "吨/辆";
    }
}
//别克车类
package com.leasesystem.car;

public class Pickup extends Vehicle {

    public Pickup() {
            this.id = 6;
            this.type = "皮卡车";
            this.price = 600;
            this.capacity = 1;
            this.capaUnit = "吨/辆";
    }
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

张飞的猪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值