继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

租车系统 (待完善) 20170623

Luning
关注TA
已关注
手记 1
粉丝 6
获赞 1

//父类
public class Vehicle {
public String name;
public double fee;
public int passengercapacity;
public int goodcapacity;

public void showparameters(){
    System.out.println(name+fee+passengercapacity+goodcapacity);
}

public double getfee(int day){          //计算费用
    return this.fee*day;
}

}

//子类 载人汽车
public class Car extends Vehicle {
public Car(String name,double fee,int passengercapacity){
this.name = name;
this.fee = fee;
this.passengercapacity = passengercapacity;
}

public void showparameters(){
    System.out.println(name+fee+"元/天  "+"载人:"+passengercapacity);
}

}

//子类 载人货车
public class Truck extends Vehicle {
public Truck(String name,double fee,int goodcapacity){
this.name = name;
this.fee = fee;
this.goodcapacity = goodcapacity;
}

public void showparameters(){
    System.out.println(name+fee+"元/天  "+"载货:"+goodcapacity);
}

}

//子类 皮卡
public class PickupTruck extends Vehicle {
public PickupTruck(String name,double fee,int passengercapacity,int goodcapacity){
this.name = name;
this.fee = fee;
this.passengercapacity = passengercapacity;
this.goodcapacity = goodcapacity;
}

public void showparameters(){
    System.out.println(name+fee+"元/天  "+"载人:"+passengercapacity+"  载货:"+goodcapacity);
}

}

//入口
public class SystemEntrance {

private Scanner scan;

//显示欢迎
public void showwelcome(){
    System.out.println("欢迎使用租车系统");
    System.out.println("您是否要租车? 1.是  2.否");
    scan = new Scanner(System.in);
    int choose = scan.nextInt();
    if(choose==2){                                      //用户退出
        System.out.println("交易关闭");
        System.exit(0);                                 //结束
    }
}

//显示可用车辆信息
public void showmessage(Vehicle[] vehicle){
    for(int i=1;i<7;i++){
        System.out.print(i+".  ");                      //显示序号
        vehicle[i-1].showparameters();
    }
}

//选择结算
public void choosevehicle(Vehicle[] vehicle){
    int i = 1;
    int days ;
    double totalfee = 0;
    System.out.println("请输入要租用的汽车数量:");
    scan = new Scanner(System.in);
    int choosecount = scan.nextInt();                   //用户选车数量
    int chooselist[] = new int[choosecount];            //所选车序号
    while(i<=choosecount){
        System.out.println("请输入第"+i+"辆车的序号");
        chooselist[i-1] = scan.nextInt();
        i++;
    }
    System.out.println("请输入要租赁的天数:");
    days = scan.nextInt();                              //用户租赁天数

    System.out.println("您的账单为");

    for(i=0;i<choosecount;i++){                         //计算费用
        totalfee += vehicle[i].getfee(days);
    }

    System.out.println("总费用:"+totalfee);
}

//入口函数
public static void main(String[] args) {
    // TODO Auto-generated method stub
    Vehicle[] vehiclelist = {new Car("奥迪A4   ", 500, 4),new Car("马自达6  ",400,4),new PickupTruck("皮卡雪      ",450,4,2),new Car("金龙         ",800,20),new Truck("松花江      ",400,4),new Truck("依维柯      ",1000,20)}; 
    SystemEntrance se = new SystemEntrance();
    se.showwelcome();
    se.showmessage(vehiclelist);
    se.choosevehicle(vehiclelist);
}

}

打开App,阅读手记
1人推荐
发表评论
随时随地看视频慕课网APP