import java.util.Observable;import java.util.Stack;class CalculatorEngine extends Observable	{	private int state;	private Stack ops;	private Op op;		CalculatorEngine()		{ this.clear(); }		Stack ops()		{ return this.ops; }		void ops( Stack aStack )		{ this.ops = aStack; }	Op op()		{ return this.op; }			void op( Op anOp )		{ this.op = anOp; }	public void notifyObservers()		{		setChanged();		notifyObservers( ops().peek() );		}			synchronized void digit( String aString )		{		String temp;		if ( state == 3 )			{			ops().push( "0" );			state = 4;			}		if ( state == 7 )			{			clear();			};					temp =  (String) ops().pop();		if ( ( state == 1 ) || ( state == 5 ) )			{			temp = temp + "." + aString;			if ( state == 1 )				{				state = 2;				}			else if ( state == 5 )				{				state = 6;				};			}		else			{			temp = temp + aString;			};				ops.push( temp );		notifyObservers();		}		synchronized void period()		{		if ( state == 0 )			{			state = 1;			}		else if ( state == 3 )			{			ops().push( "0" );			state = 5;			}		else if ( state == 4 )			{			state = 5;			}		else if ( state == 7 )			{			clear();			state = 1;			};		}		synchronized void operation( Op anOp )		{		if ( anOp.isBinaryOp() )			{			binaryOperation( anOp );			state = 3;			}		else			{			unaryOperation( anOp );			};		notifyObservers();		}		void binaryOperation( Op anOp )		{		if ( ( state == 4 ) || (state == 5) || (state == 6) )			{			Double temp1;			Double temp2;			 			temp2 = ( new Double( (String) (ops().pop()) ) );			temp1 = ( new Double( (String) (ops().pop()) ) );			ops().push( op().perform( temp1, temp2 ).toString() );				};		op( anOp );		}		void unaryOperation( Op anOp )		{		Double temp;				temp = ( new Double( (String) (ops().pop()) ) );		ops().push( anOp.perform( temp ).toString() );		}				synchronized void clear()		{		ops( new Stack() );		ops().push( "0" );		op( null );		state = 0;				notifyObservers();		}		synchronized void calculate()		{		binaryOperation( null );		state = 7;				notifyObservers();		}			}