|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--edu.hws.jcm.data.Constant
A Constant is a Value that represents a constant real number. (The value doesn't have to be constant in sub-classes, since the member that stores the value is protected, not private.) A Constant doesn't necessarily need a name. If the name is null, then the print string for the Constant is the value of the constant. If it has a non-null name, then the print string is the name. (Note that, as for any MathObject, if the name is null, than the Constant can't be added to a Parser.) Constant objects are used to represent the mathematical constants pi and e. A Constant is both an Expression and an ExpressionCommand. Since it is an ExpressionCommand, it can occur as a command in an ExpressionProgram. In that case, it simply represens a named constant occurs in an expression.
Field Summary | |
protected double |
value
The value of this Constant. |
Constructor Summary | |
Constant(double value)
Create an unnamed Constant with the given value and null name. |
|
Constant(java.lang.String name,
double value)
Create a Constant with the given name and value. |
Method Summary | |
void |
appendOutputString(ExpressionProgram prog,
int myIndex,
java.lang.StringBuffer buffer)
Append the print string for this Constant to the buffer. |
void |
apply(StackOfDouble stack,
Cases cases)
Apply the Constant to the stack. |
void |
compileDerivative(ExpressionProgram prog,
int myIndex,
ExpressionProgram deriv,
Variable wrt)
Add a commands to deriv to evaluate the derivative of this Constant with respect to the variable. |
boolean |
dependsOn(Variable x)
Retrun false, since the value of this Constant is independent of the value of x. |
Expression |
derivative(Variable wrt)
Return the derivative of this Constant with respect to the variable wrt. |
int |
extent(ExpressionProgram prog,
int myIndex)
Return the number of locations that this Constant uses in the program. |
java.lang.String |
getName()
Return the name of this Constant. |
double |
getVal()
Return the value of this Constant. |
double |
getValueWithCases(Cases cases)
Return the value of the Constant. |
void |
setName(java.lang.String name)
Set the name of this Constant. |
java.lang.String |
toString()
Return the print string representing this Constant. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected double value
Constructor Detail |
public Constant(double value)
public Constant(java.lang.String name, double value)
Method Detail |
public java.lang.String getName()
getName
in interface MathObject
public void setName(java.lang.String name)
setName
in interface MathObject
public double getVal()
getVal
in interface Value
public double getValueWithCases(Cases cases)
getValueWithCases
in interface Expression
public Expression derivative(Variable wrt)
derivative
in interface Expression
public java.lang.String toString()
toString
in interface Expression
toString
in class java.lang.Object
public void apply(StackOfDouble stack, Cases cases)
apply
in interface ExpressionCommand
edu.hws.jcm.data.ExpressionCommand
stack
- contains results of previous commands in the program.cases
- if non-null, any case information generated during evaluation should be recorded here.public void compileDerivative(ExpressionProgram prog, int myIndex, ExpressionProgram deriv, Variable wrt)
compileDerivative
in interface ExpressionCommand
edu.hws.jcm.data.ExpressionCommand
prog
- program in which ExpressionCommand occurs.myIndex
- point at which ExpressionCommand occurs in the ExpressionProgram.deriv
- the derivative of the ExpressionPorgram prog, which is in the process of being computed.
Commands should added to deriv that will compute the derivative of this ExpressionCommand.wrt
- commands are added to deriv with respect to this Variable.public int extent(ExpressionProgram prog, int myIndex)
extent
in interface ExpressionCommand
edu.hws.jcm.data.ExpressionCommand
prog
- ExpressionProgram in which this ExpressionCommand occurs.myIndex
- index at which ExpressionCommand occurs in prog.public boolean dependsOn(Variable x)
dependsOn
in interface Expression
public void appendOutputString(ExpressionProgram prog, int myIndex, java.lang.StringBuffer buffer)
appendOutputString
in interface ExpressionCommand
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |