ComputerTime.java 源程序:
import pkg1.pkg2.*;
import java.lang.*;
public class ComputerTime{
public static void main(String args[]){
System.out.println("交通工具: "+args[0]);
System.out.println(" 参数A: "+args[1]);
System.out.println(" 参数B: "+args[2]);
System.out.println(" 参数C: "+args[3]);
double A=Double.parseDouble(args[1]);
double B=Double.parseDouble(args[2]);
double C=Double.parseDouble(args[3]);
double v,t;
try { Common d=(Common) Class.forName("pkg1."+args[0]).newInstance();
v=d.runtimer(A,B,C);
t=1000/v;
System.out.println("平均速度: "+v+" km/h");
System.out.println("运行时间:"+t+" 小时");
}
catch(Exception e){
System.out.println("class not found");
}
}
}
包pkg1中Car007.java的源程序:
package pkg1;
import pkg1.pkg2.*;
public class Car007 implements Common{
public double runtimer(double A,double B,double C{
System.out.println("runtime="+(A*B/C));
return A*B/C;
}
}
包pkg1中Plane.java的源程序:
package pkg1;
import pkg1.pkg2.*;
public class Plane implements Common{
public double runtimer(double A,double B,double C){
return A+B+C;
}
}
包pkg2中Common.java的源程序:
package pkg1.pkg2;
public interface Common{
double runtimer(double A,double B,double C);
}
要怎么做才可以运行上面的那几个程序呢!?