交通工具


用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();
	}

}


  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值