适配器设计模式---接口适配

package cn.icer.simulation.InterfaceAdapter;

/**
 * 火箭
 * @author icer
 * @date:2013-12-27
 *
 */
public interface SkyRocket {

	/**
	 *
	 * @return 燃料的剩余量
	 */
	public abstract double getMass();
	
	/**
	 * 
	 * @return 产生的推力
	 */
	public abstract double getThrust();
	
	/**
	 * 
	 * @param time 燃烧时间
	 */
	public abstract void setSimTime(double time);
}

package cn.icer.simulation.InterfaceAdapter;

/**
 * 火箭
 * @author icer
 * @date 2013-12-27
 *
 */
public class PhysicalRocket {

	private double burnArea;			//燃烧面积
	private double burnRate;			//燃烧率
	private double initFuelMass;		//燃料
	private double totalMass;			//燃料总量
	
	
	private double totalBurnTime;		//总燃烧时间
	
	//重力加速度
	private static double SPECIFIC_IMPULSE = 620;		// Newtons/Kg
	
	//燃料密度
	private static double FUEL_DENSITY = 1800;			// Kg / M**3
	
	public PhysicalRocket(double burnArea, double burnRate, double fuelMass, double totalMass) {
		this.burnArea = burnArea;
		this.burnRate = burnRate;
		this.initFuelMass = fuelMass;
		this.totalMass = totalMass;
		
		double initialFuelVolume = fuelMass / FUEL_DENSITY;
		
		this.totalBurnTime = initialFuelVolume / (burnArea * burnRate);
	}
	
	/**
	 * 
	 * @return 燃烧时间
	 */
	public double getBurnTime()
	{
		return totalBurnTime;
	}
	
	/**
	 * 
	 * @param time 燃烧时间
	 * @return 现在剩余的燃料
	 */
	public double getMass(double time)
	{
		if ( time > totalBurnTime)
			return totalMass - initFuelMass;
		
		double burntFuelVolume = burnArea * burnRate * time;
		
		return totalMass - burntFuelVolume * FUEL_DENSITY;
	}
	
	/**
	 * 
	 * @param time 燃烧时间
	 * @return 点火以来产生的总推力
	 */
	public double getThrust(double time)
	{
		if (time > totalBurnTime)
			return 0;
		
		return FUEL_DENSITY * SPECIFIC_IMPULSE * burnArea * burnRate;
	}
}

package cn.icer.simulation.InterfaceAdapter;

/**
 * 火箭
 * @author icer
 * @date 2013-12-27
 *
 */
public class IcerRocket extends PhysicalRocket implements SkyRocket {

	private double time;
	
	public IcerRocket(double burnArea, double burnRate, double fuelMass,
			double totalMass) {
		super(burnArea, burnRate, fuelMass, totalMass);
	}

	@Override
	public double getMass() {
		return getMass(time);
	}

	@Override
	public double getThrust() {
		return getThrust(time);
	}

	@Override
	public void setSimTime(double time) {
		this.time = time;
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值