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


Constructor Index

 o Calculation(int)
This is the constructor for the calculator.

Method Index

 o execute()
MethodName: execute()
Purpose: This method is called after the execution stack has been loaded.
 o getExecutionResult()
MethodName: getExecutionResult()
Purpose: This method is called after the execution stack has been executed.
 o pushOperand(Calculation)
Method Name: pushOperand
Purpose: This method will push a calculation operand onto the
execution stack.
 o pushOperand(double)
Method Name: pushOperand
Purpose: This method will push a double operand onto the
execution stack.
 o pushOperand(float)
Method Name: pushOperand
Purpose: This method will push a float operand onto the
execution stack.
 o pushOperand(int)
Method Name: pushOperand
Purpose: This method will push an integer operand onto the
execution stack.
 o pushOperand(long)
Method Name: pushOperand
Purpose: This method will push long integer operand onto the
execution stack.
 o pushOperand(String)
Method Name: pushOperand
Purpose: This method will push a string operand onto the
execution stack.
 o pushOperator(String[])
Method Name: pushOperator
Purpose: This method will receive a String dictating the operator
to push on the stack.
 o removeOperand()
Method Name: removeOperand
Purpose: This method will remove the top-most operand from the
execution stack.
 o removeOperator()
Method Name: removeOperator
Purpose: This method will remove the top-most operator from the
execution stack.
 o removeTopMostElement()
Method Name: removeTopMostElement
Purpose: This method will remove the top-most element, regardless if it is
an operand or operator.

Constructors

 o 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.

Methods

 o 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.

 o 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.

 o 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.

 o 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.

 o 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.

 o 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.

 o 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.

 o 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.

 o 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.

 o 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

 o 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.

 o 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