用JAVA为某研究所编写一个通用程序,用来计算每一种交通工具运行1000公里所需的时间,已知速度ABC,求速度
数都是3个整数A、B、C的表达式.现有两种工具:Car007 和Plane,其中Car007 的速度运算公式为:A*B/C,Plane 的速度运算公式为:A+B+C
//Common.java
public interface Common {
float calculateVelocity(int a,int b,int c);
}
//Car.java
public class Car007 implements Common{
public float calculateVelocity(int a, int b, int c) {
return a*b/(float)c;
}
}
//Plane.java
public class Plane implements Common {
public float calculateVelocity(int a, int b, int c) {
return a+b+c;
}
}
//ComputeTime.java
import java.util.*;
public class ComputeTime {
public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
String transport;
Scanner reader=new Scanner(System.in);
transport=(String)reader.next();
int a=reader.nextInt(),b=reader.nextInt(),c=reader.nextInt();
Common atransport=(Common)Class.forName(transport).newInstance();
System.out.println(atransport.calculateVelocity(a, b, c));
reader.close();
}
}