All Packages Class Hierarchy This Package Previous Next Index
Class designer.Calculation
java.lang.Object
|
+----designer.Calculation
- public class Calculation
- extends Object
Class: Calculation
Purpose:
This class provides our design problem solver the capability of evaulating
arithmetic expressions. Architecturally, it is a stack-based arithmetic
calculator, capable of all the functions native to JDK v1.1. This stack-based
machine will be capable of evaluating an expression in an RPN fashion. Supported
expressions are the same set as supported in JDK v1.1
-
Calculation(int)
- This is the constructor for the calculator.
-
execute()
- MethodName: execute()
Purpose: This method is called after the execution stack has been loaded.
-
getExecutionResult()
- MethodName: getExecutionResult()
Purpose: This method is called after the execution stack has been executed.
-
pushOperand(Calculation)
- Method Name: pushOperand
Purpose: This method will push a calculation operand onto the
execution stack.
-
pushOperand(double)
- Method Name: pushOperand
Purpose: This method will push a double operand onto the
execution stack.
-
pushOperand(float)
- Method Name: pushOperand
Purpose: This method will push a float operand onto the
execution stack.
-
pushOperand(int)
- Method Name: pushOperand
Purpose: This method will push an integer operand onto the
execution stack.
-
pushOperand(long)
- Method Name: pushOperand
Purpose: This method will push long integer operand onto the
execution stack.
-
pushOperand(String)
- Method Name: pushOperand
Purpose: This method will push a string operand onto the
execution stack.
-
pushOperator(String[])
- Method Name: pushOperator
Purpose: This method will receive a String dictating the operator
to push on the stack.
-
removeOperand()
- Method Name: removeOperand
Purpose: This method will remove the top-most operand from the
execution stack.
-
removeOperator()
- Method Name: removeOperator
Purpose: This method will remove the top-most operator from the
execution stack.
-
removeTopMostElement()
- Method Name: removeTopMostElement
Purpose: This method will remove the top-most element, regardless if it is
an operand or operator.
Calculation
public Calculation(int iExecutionStackSize)
- This is the constructor for the calculator. It simply allocates
all instance data (i.e. the stack) and awaits for something to input.
pushOperand
public void pushOperand(int intOperand)
- Method Name: pushOperand
Purpose: This method will push an integer operand onto the
execution stack.
PRE: Nothing.
POST: Stack must not be empty, the last object placed is the one
passed a a parameter. The size of the stack must be one more than
it was before the insertion.
pushOperand
public void pushOperand(long longOperand)
- Method Name: pushOperand
Purpose: This method will push long integer operand onto the
execution stack.
PRE: Nothing.
POST: Stack must not be empty, the last object placed is the one
passed a a parameter. The size of the stack must be one more than
it was before the insertion.
pushOperand
public void pushOperand(float floatOperand)
- Method Name: pushOperand
Purpose: This method will push a float operand onto the
execution stack.
PRE: Nothing.
POST: Stack must not be empty, the last object placed is the one
passed a a parameter. The size of the stack must be one more than
it was before the insertion.
pushOperand
public void pushOperand(double doubleOperand)
- Method Name: pushOperand
Purpose: This method will push a double operand onto the
execution stack.
PRE: Nothing.
POST: Stack must not be empty, the last object placed is the one
passed a a parameter. The size of the stack must be one more than
it was before the insertion.
pushOperand
public void pushOperand(String stringOperand)
- Method Name: pushOperand
Purpose: This method will push a string operand onto the
execution stack.
PRE: Nothing.
POST: Stack must not be empty, the last object placed is the one
passed a a parameter. The size of the stack must be one more than
it was before the insertion.
pushOperand
public void pushOperand(Calculation calculationOperand)
- Method Name: pushOperand
Purpose: This method will push a calculation operand onto the
execution stack.
PRE: Nothing.
POST: Stack must not be empty, the last object placed is the one
passed a a parameter. The size of the stack must be one more than
it was before the insertion.
pushOperator
public boolean pushOperator(String operatorNameAndParameterTypes[])
- Method Name: pushOperator
Purpose: This method will receive a String dictating the operator
to push on the stack. Operators will be selected from an UI, which
is sort of a trusted source. Operators will be checked for validity and
compliance with JDK v1.1 operators. The only other operators, atomic operators
are "+", "-", "*" or "/".
PRE: operator must be one of the defined operators.
POST: Stack must not be empty, the last object placed is the one
passed a a parameter. The size of the stack must be one more than
it was before the insertion. If false is returned, the operator was
not a valid java.lang.Math or Atomic operator.
removeOperand
public void removeOperand()
- Method Name: removeOperand
Purpose: This method will remove the top-most operand from the
execution stack.
PRE: The top object in the execution stack must be an operand (of type
PushableOperand.
POST: The size of the execution stack must be one less than it was.
removeOperator
public void removeOperator()
- Method Name: removeOperator
Purpose: This method will remove the top-most operator from the
execution stack.
PRE: The top object in the execution stack must be an operator (of
type String) and a valid operator.
POST: The size of the execution stack must be one less than it was.
removeTopMostElement
public void removeTopMostElement()
- Method Name: removeTopMostElement
Purpose: This method will remove the top-most element, regardless if it is
an operand or operator.
PRE: The execution stack must not be empty.
POST: Nothing
execute
public boolean execute()
- MethodName: execute()
Purpose: This method is called after the execution stack has been loaded.
This execution stack assumes operators/operands have been loaded onto the
execution stack in a RPN format.
PRE: Top-most element of the execution stack is an operator.
POST: Result is the top-most element of the stack. The result is the
only element on the execution stack.
getExecutionResult
public Number getExecutionResult()
- MethodName: getExecutionResult()
Purpose: This method is called after the execution stack has been executed.
PRE: Only one element on the execution stack. If the element is not a Number
null is returned.
POST: Execution stack empty
All Packages Class Hierarchy This Package Previous Next Index