为了账号安全,请及时绑定邮箱和手机立即绑定

租车系统 (待完善) 20170623

标签:
Java

//父类
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);
}

}

点击查看更多内容
1人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消