ITPub博客

首页 > IT职业 > IT职场 > 嗒嗒租车系统!!!!!

嗒嗒租车系统!!!!!

IT职场 作者:mpsky 时间:2021-09-09 08:56:58 0 删除 编辑

参考了很多别人写的,然后写出来的。。
Car.java

package com.imooc.recentcar;

public class Car {
    private int carNumber;//汽车编号
    private String carName;//汽车名字
    private int carPrice;//汽车价格
    private int loadPeople;//载客量
    private int loadGoods;//载货量

    //获取汽车编号
    public int getCarNumber(){
        return carNumber;
    }
    public void setCarNumber(int carNumber){
        this.carNumber = carNumber;
    }
    //获取汽车名字
    public String getCarName(){
        return carName;
    }
    public void setCarName(String carName){
        this.carName = carName;
    }
    //获取汽车价格
    public int getCarPrice(){
        return carPrice;
    }
    public void setCarPrice(int carPrice){
        this.carPrice = carPrice;
    }
    //获取汽车载客量
    public int getLoadPeople(){
        return loadPeople;
    }
    public void setLoadPeople(int loadPeople){
        this.loadPeople = loadPeople;
    }
    //获取汽车载客量
    public int getLoadGoods(){
        return loadGoods;
    }
    public void setLoadGoods(int loadGoods){
        this.loadGoods = loadGoods;
    }
}

Coach.java

package com.imooc.recentcar;

public class Coach extends Car {
    public Coach(int carNumber,String carName,int carPrice,int loadPeople){
        this.setCarNumber(carNumber);
        this.setCarName(carName);
        this.setCarPrice(carPrice);
        this.setLoadPeople(loadPeople);

    }

}

PickUp.java

package com.imooc.recentcar;

public class PickUp extends Car {
    public PickUp(int carNumber,String carName,int carPrice,int loadPeople,int loadGoods){
        this.setCarNumber(carNumber);
        this.setCarName(carName);
        this.setCarPrice(carPrice);
        this.setLoadPeople(loadPeople);
        this.setLoadGoods(loadGoods);
    }

}

Truck.java

package com.imooc.recentcar;

public class Truck extends Car {
    public Truck(int carNumber,String carName,int carPrice,int loadGoods){
        this.setCarNumber(carNumber);
        this.setCarName(carName);
        this.setCarPrice(carPrice);
        this.setLoadGoods(loadGoods);
    }

}

show.java

package com.imooc.recentcar;
import java.util.*;

public class show {

    public static void main(String[] args) {
        System.out.println("******欢迎使用嗒嗒租车系统******");
        System.out.println("您是否要租车:1.是;2.否");//选否则推出程序
        String shi_fou;//定义此变量用来接收用户的输入,用String类型防止用户胡乱输入
        Scanner input = new Scanner(System.in);
        int count = 0;//用来记录用户输错的次数
        while(true){
            shi_fou = input.next();//用户输入
            if(shi_fou.equals("1")){
                System.out.println("您可租车的类型及价目表:");
                Car[] carRent = {new Coach(1,"奥迪",500,4),
                                 new Coach(2,"马自达",400,4),
                                 new PickUp(3,"皮卡雪",450,4,2),
                                 new Coach(4,"金龙",800,20),
                                 new Truck(5,"松花江",400,4),
                                 new Truck(6,"解放",500,5)
                };
                System.out.println("序号"+"t"+"汽车名称"+"t"+"租金"+"t"+"载客量"+"t"+"载货量");
                for(Car car:carRent){
                    System.out.println(car.getCarNumber()+"t"+car.getCarName()+"t"+car.getCarPrice()+"/天"+"t"+car.getLoadPeople()+"人"+"t"+car.getLoadGoods()+"吨");
                }
                System.out.println("请输入您要租车的数量");
                int n=input.nextInt();
                List carList = new ArrayList();//存储用户选择的车名
                List carList1 = new ArrayList();//存储用户选择的可载客的车
                List carList2 = new ArrayList();//存储用户选择的可载货的车
                int p = 0;
                int cnum = 0;
                int tnum = 0;
                int pnum = 0;
                for(int i=0;i

运行结果:

***欢迎使用嗒嗒租车系统**
您是否要租车:1.是;2.否
1
您可租车的类型及价目表:
序号 汽车名称 租金 载客量 载货量
1 奥迪 500/天 4人 0吨
2 马自达 400/天 4人 0吨
3 皮卡雪 450/天 4人 2吨
4 金龙 800/天 20人 0吨
5 松花江 400/天 0人 4吨
6 解放 500/天 0人 5吨
请输入您要租车的数量
3
请输入第1辆车的序号:
1
成功添加奥迪
请输入第2辆车的序号:
2
成功添加马自达
请输入第3辆车的序号:
3
成功添加皮卡雪
请输入租车的天数:
3
**可载客的车有**
奥迪
马自达
皮卡雪
载客量为:12人
**可载货的车有**
皮卡雪
载货量为:2吨
**租车的总价格**
4050*


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1806/viewspace-2807356/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-07-18

  • 博文量
    115
  • 访问量
    14709