一,创建Auto类
public class Auto {
private String brand;
private double price;
private long length;
public Auto() {
}
public Auto(String brand, double price, long length) {
this.brand = brand;
this.price = price;
this.length = length;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public long getLength() {
return length;
}
public void setLength(long length) {
this.length = length;
}
}
二,创建SUV类,且继承Auto类
public class SUV extends Auto{
public static int minLen = 4295;
public static int midLen = 5070;
public SUV() {
}
public SUV(String brand, double price, long length) {
super(brand, price, length);
}
public boolean judgeMin(){
return getLength() < midLen;
}
public boolean judgeMax(){
return getLength() > midLen;
}
public boolean judgeMid(){
return getLength() <= midLen && getLength() > minLen;
}
}
三,创建测试类Test
public class Test {
public static void main(String[] args) {
SUV s1 = new SUV("本田",20000,4000);
SUV s2 = new SUV("丰田",30000,5000);
SUV s3 = new SUV("三菱",200000,4800);
SUV s4 = new SUV("红旗",2000000000,5100);
SUV[] suvs = {s1,s2,s3,s4};
for(SUV suv : suvs){
if(suv.judgeMid()){
System.out.println(suv.getBrand()+"---"+suv.getPrice()+"---"+suv.getLength());
}
}
}
}