租车系统

java练习2:
java实现模拟借书系统:
可实现:
(基本功能)
1.展示可租车辆
2.选择车型、租车量
3.展示租车清单,包含:总金额、总载货量及其车型、总载人量及其车型
(异常处理)
1.输入类型错误,输出“are you kidding me?”,提示重新输入
2.超过车辆库的范围,输出“序号超出范围”,提示重新输入
3.对于不符合常识的数量和日期,输出“请输入大于或等于1的整数!”,提示重新输入

界面:


图片1.png
public class Car {
    private int seq;
    private String name;
    private int money;
    public int getSeq() {
        return seq;
    }
    public void setSeq(int seq) {
        this.seq = seq;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getMoney() {
        return money;
    }
    public void setMoney(int money) {
        this.money = money;
    }
}
public class RenCar extends Car {
    private int people;
    public RenCar(int seq,String name,int money,int people) {
        this.setSeq(seq);
        this.setName(name);
        this.setMoney(money);
        this.people=people;
    }
    public int getPeople() {
        return people;
    }
    public void setPeople(int people) {
        this.people = people;
    }
}
public class picar extends Car {
    private int people;
    private int thing;
    public picar(int seq,String name,int money,int people,int thing) {
        this.setSeq(seq);
        this.setName(name);
        this.setMoney(money);
        this.people=people;
        this.thing=thing;
    }
    public int getPeople() {
        return people;
    }
    public void setPeople(int people) {
        this.people = people;
    }
    public int getThing() {
        return thing;
    }
    public void setThing(int thing) {
        this.thing = thing;
    }
}
public class Trunk extends Car {
    private int thing;
    public Trunk(int seq,String name,int money,int thing) {
        this.setSeq(seq);
        this.setName(name);
        this.setMoney(money);
        this.thing=thing;
    }
    public int getThing() {
        return thing;
    }
    public void setThing(int thing) {
        this.thing = thing;
    }
}
import java.util.Scanner;
public class Initail {
    private static Scanner sc=new Scanner(System.in);
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        //车辆信息
        Car[] cars= {new RenCar(1,"奥迪A4",500,4),new RenCar(2,"马自达6",400,4),new picar(3,"皮卡雪6",450,4,2),new RenCar(4,"金龙",800,20),new Trunk(5,"松花江",400,4),new Trunk(6,"依维柯",1000,20)};
        System.out.println("******欢迎使用哒哒租车系统:");
        System.out.println("*****您是否要租车:1是  0否;");
        while(true) {
            int a1=selectNum();
            switch(a1) {
                case 1://租车 
                 // 租车表显示
                    System.out.println("****您可租车的类型及其价目表:");
                    System.out.println("序号"+"\t汽车名称"+"\t租金(元)"+"\t载人(人)"+"\t载货(吨)");
                    for(Car car:cars) {
                        if(car instanceof RenCar) {
                            System.out.println(car.getSeq()+"\t"+car.getName()+"\t"
                        +car.getMoney()+"\t"+((RenCar) car).getPeople());
                        }else if(car instanceof picar) {
                            System.out.println(car.getSeq()+"\t"+car.getName()+"\t"
                        +car.getMoney()+"\t"+((picar) car).getPeople()+"\t"+((picar) car).getThing());
                        }else {
                            System.out.println(car.getSeq()+"\t"+car.getName()+"\t"
                        +car.getMoney()+"\t"+"\t"+((Trunk) car).getThing());
                        }
                    }
                        //开始租车
                    System.out.println("****请输入您要租汽车的数量:");
                    int a2=selectDateOrNumber();
                    int[] seq=new int[a2];
                    for(int i=0;icars.length) {
                    System.out.print("序号超出范围!");
                    continue;
                }
                int number=cars[seq-1].getSeq();
                return number;
        }
    }
}

你可能感兴趣的:(租车系统)