建两个类,建立继承关系计算行驶公里

img



```java

public class TestClass {
    public static void main(String[] args) {
        Bus b=new Bus("金龙牌","Gl-0012",200.0,3.0,50);
        System.out.println(b.getGongli(200.0, 1.0));
        System.out.println(b.getGongli(100.0, 2.0));
        
        Car c=new Car("宝马","X5",50.0,7.0);
        System.out.println(c.getGongLi());
    }
}

class Car{
    private String brand;
    private String type;
    private Double ranRl;
    private Double youRl;
    public Car() {}
    public Car(String brand, String type, Double ranRl, Double youRl) {
        this.brand = brand;
        this.type = type;
        this.ranRl = ranRl;
        this.youRl = youRl;
    }
    public Car(String brand, String type) {
        this.brand = brand;
        this.type = type;
    }
    public Car( Double ranRl, Double youRl) {
        this.ranRl = ranRl;
        this.youRl = youRl;
    }
    public String getBrand() {
        return brand;
    }
    public void setBrand(String brand) {
        this.brand = brand;
    }
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public Double getRanRl() {
        return ranRl;
    }
    public void setRanRl(Double ranRl) {
        this.ranRl = ranRl;
    }
    public Double getYouRl() {
        return youRl;
    }
    public void setYouRl(Double youRl) {
        this.youRl = youRl;
    }
    public String getMsg() {
        return this.brand+"\t"+this.type;
    }
    public Double getGongLi() {
        return this.youRl/this.ranRl*100;
    }
}
class Bus extends Car{
    private int count;
    
    public int getCount() {
        return count;
    }
    public void setCount(int count) {
        this.count = count;
    }
    public String getSMsg() {
        return super.getMsg()+this.count;
    }
    public Double getGongLi() {
        return this.getYouRl()/this.getRanRl()/this.count*100;
    }
    public Double getGongli(Double youl,Double renShu) {
        return youl/this.getRanRl()/renShu*100;
    }
    public Bus(String brand, String type, Double ranRl, Double youRl,Integer c) {
        super(brand,type,ranRl,youRl);
        this.count=c;
    }
}



```