这是一个关于 调用对象的问题
public class test{
public static void main(String args[])
{
Car car=new Car(1.55,2.80);
car.speed=100;
String name=("宝马");
double d=car.getDistance(10);
double h=car.getHigh();
double l=car.getLength();
System.out.println("车名为:"+name);
System.out.println("汽车的速度为每小时"+car.speed+"千米");
System.out.println("10小时跑了"+d+"千米");
System.out.println("该汽车高"+h+"米");
System.out.println("该汽车长"+l+"米");
System.out.println("==========================================");
Car car1=new Car(1.65,3.00);
car1.speed=200;
String name1=("奔驰");
double k=car1.getDistance(5);
double m=car1.getHigh();
double n=car1.getLength();
System.out.println("车名为:"+name1);
System.out.println("汽车的速度为每小时"+car1.speed+"千米");
System.out.println("5小时跑了"+k+"千米");
System.out.println("该汽车高"+m+"米");
System.out.println("该汽车长"+n+"米");
System.out.println("==========================================");
Car car2=new Car(1.45,3.80);
car2.speed=150;
String name2=("加长版林肯");
double k1=car2.getDistance(1);
double m1=car2.getHigh();
double n1=car2.getLength();
System.out.println("车名为:"+name2);
System.out.println("汽车的速度为每小时"+car2.speed+"千米");
System.out.println("1小时跑了"+k1+"千米");
System.out.println("该汽车高"+m1+"米");
System.out.println("该汽车长"+n1+"米");
}
}
class Car{
double speed;
double high;
double length;
public Car(double h,double l){
high=h;
length=l;
}
public double getDistance(int s){
return speed*s;
}
public double getHigh(){
return high;
}
public double getLength(){
return length;
}
}
这个看起来太烦琐了 有没有简单的方法请指教`