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

汽车租赁系统代码实例编写

裥簞點
关注TA
已关注
手记 3
粉丝 0
获赞 27
package com.imooc2;

public class Car {
    double rent;
    String name;
    double cargoCapacity;
    double peopleCapacity;
    public String getName(){
        return name;
    }
    public double getRent(){
        return rent;
    }
}

package com.imooc2;

public class passengerCar extends Car {
    private double peopleCapacity;
    public passengerCar(String name, double rent, double peopleCapacity){
        this.name=name;
        this.rent=rent;
        this.peopleCapacity=peopleCapacity;
    }
    public double getPeopleCapacity(){
        return peopleCapacity;
    }
    public void setPeopleCapacity(double peopleCapacity){
        this.peopleCapacity=peopleCapacity;
    }
}

package com.imooc2;

public class Pickup extends Car {
    private double cargoCapacity;
    private double peopleCapacity;
    public Pickup(String name, double rent, double cargoCapacity,double peopleCapacity){
        this.name=name;
        this.rent=rent;
        this.cargoCapacity=cargoCapacity;
        this.peopleCapacity=peopleCapacity;
    }
    public double getCargoCapacity(){
        return cargoCapacity;
    }
    public void setCargoCapacity(double cargoCapacity){
        this.cargoCapacity=cargoCapacity;
    }
    public double getPeopleCapacity(){
        return peopleCapacity;
    }
    public void setPeopleCapacity(double peopleCapacity){
        this.peopleCapacity=peopleCapacity;
    }
}

package com.imooc2;

public class Trunk extends Car {
    private double cargoCapacity;
    public Trunk(String name, double rent, double cargoCapacity){
        this.name=name;
        this.rent=rent;
        this.cargoCapacity=cargoCapacity;
    }
    public double getCargoCapacity(){
        return cargoCapacity;
    }
    public void setCargoCapacity(double cargoCapacity){
        this.cargoCapacity=cargoCapacity;
    }
}

package com.imooc2;

import java.util.Scanner;

public class Test {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Car[] carsForRent={new passengerCar("奥迪A4",500,4),new passengerCar("马自达6",400,4),new Pickup("皮卡雪6",450,4,2),new passengerCar("金龙",800,20),new Trunk("松花江",400,4),new Trunk("依维柯",1000,20)};
        System.out.println("欢迎使用答答租车系统:");
        System.out.println("您是否需要租车:1是 0否");
        Scanner scan=new Scanner(System.in);
        String input=scan.next();
        if(input.equals("1")){
            System.out.println("你可租车的类型机器价目表:");
            System.out.println("序号\t汽车名称\t租金\t\t容量");
            int i=0;
            for(Car currentCar:carsForRent){
                if(currentCar instanceof passengerCar){
                    System.out.println(""+i+"\t"+currentCar.getName()+"\t"+currentCar.getRent()+"元/天\t"+((passengerCar)currentCar).getPeopleCapacity()+"人");
                }
                if(currentCar instanceof Trunk){
                    System.out.println(""+i+"\t"+currentCar.getName()+"\t"+currentCar.getRent()+"元/天\t"+((Trunk)currentCar).getCargoCapacity()+ "吨");
                }
                if(currentCar instanceof Pickup){
                    System.out.println(""+i+"\t"+currentCar.getName()+"\t"+currentCar.getRent()+"元/天\t"+((Pickup)currentCar).getPeopleCapacity()+"人"+((Pickup)currentCar).getCargoCapacity()+"吨");
                }
                i++;
            }
            System.out.println("请选择所租车序号:");
            Scanner num=new Scanner(System.in);
            int nums=num.nextInt();
            System.out.println("请选择租车天数:");
            Scanner day=new Scanner(System.in);
            int days=num.nextInt();
            double count;
            count=(carsForRent[nums].getRent())*days;
            System.out.println("应支付租金:"+count);

        }
    }

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