适配器设计模式---对象适配

package cn.icer.simulation.ObjectAdapter;

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

	private double burnTime;
	private double mass;
	private double thrust;
	
	public SkyRocket(double mass, double thrust, double burnTime)
	{
		this.mass = mass;
		this.thrust = thrust;
		this.burnTime = burnTime;
	}
	
	public abstract double getMass();
	
	public abstract double getThrust();
	
	public abstract void setSimTime(double time);
	
}

package cn.icer.simulation.ObjectAdapter;

/**
 * 火箭
 * @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.ObjectAdapter;

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

	private double time;
	
	private PhysicalRocket rocket;

	public IcerRocket(PhysicalRocket rocket) {
		super(rocket.getMass(0), rocket.getThrust(0), rocket.getBurnTime());
		
		this.rocket = rocket;
	}

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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值