Class : ComplexFunction - VadimKachevski/OOP_Ex1 GitHub Wiki

The Class ComplexFunction is implementing complex_function interface which extends function.


Every complex function is holding:

  • Operation
  • function left
  • function right

function can be a Monom,Polynom or another ComplexFunction.

The Operation can as follows:

  • Plus- Computes and returns the Y value of (left function + right function) at the point X.
  • mul- Computes and returns the Y value of (left function * right function) at the point X.
  • div- Computes and returns the Y value of (left function / right function) at the point X.
  • max- Computes and returns the Y value of max(leftFunction(x),rightFunction(x)).
  • min- Computes and returns the Y value of min(leftFunction(x),rightFunction(x)).
  • comp- Computes and returns the Y value of (leftfunction(rightfunction(x)),Computes the Y value of rightfunction at the point X and computes this Value as the x for the left function.
  • none- Only viable if right function Is NULL so it returns the value Y of leftFucntion at the point x.

The Methods that can be used with the ComplexFunction object :

There are 4 ways to create a ComplexFunction:

  • ComplexFunction(String str)- When receiving a String it will try to create a ComplexFunction with the given String. Vaild Strings:
  1. plus(-1.0x^4+2.4x^2+3.1,0.1x^5-1.2999999999999998x+5.0)
  2. plus(div(1.0x+1.0,mul(mul(1.0x+3.0,1.0x-2.0),1.0x-4.0)),2.0)
  3. div(plus(-1.0x^4+2.4x^2+3.1,0.1x^5-1.2999999999999998x+5.0),-1.0x^4+2.4x^2+3.1)
  4. -1.0x^4+2.4x^2+3.1
  • ComplexFunction(Operation op,function left,function right) - Receiving a ENUM Operation, function left and function right, if the operation is not NONE, both left and right should not be NULL, if its NONE, right can be NULL. left can never be NULL.
  • ComplexFunction(String op,function left,function right) - Receiving a String as the Operation can have any and only of the following operations : "plus","mul" , "div", "max", "min", "comp", "none" . if the operation is not NONE, both left and right should not be NULL, if its NONE, right can be NULL. left can never be NULL.
  • ComplexFunction(function left) - receiving only function left,which mean sets the Operation to None.

Other methods that can be used in the ComplexFunction object

  • f(double x) - returns the Y value of ComplexFunction with the given X.
  • initFromString(String s) - returns a function created from the given String.
  • function copy() - returns a function that is a deep copy of the current ComplexFunction.
  • plus(function f1)- setting the current Complex function as the left function,setting f1 as the right function and setting the Operation as Plus.
  • mul(function f1) - setting the current Complex function as the left function,setting f1 as the right function and setting the Operation as Times.
  • div(function f1) - setting the current Complex function as the left function,setting f1 as the right function and setting the Operation as Divid.
  • max(function f1) - setting the current Complex function as the left function,setting f1 as the right function and setting the Operation as Max.
  • min(function f1) - setting the current Complex function as the left function,setting f1 as the right function and setting the Operation as Min.
  • comp(function f1) - setting the current Complex function as the left function,setting f1 as the right function and setting the Operation as Comp.
  • left() - returns the left function.
  • right() - returns the right function.
  • getOp() - returns the Operation.
  • toString() - returns the String value that represent the current ComplexFunction.
  • equals(Object other) - returns a boolean value if the current Polynom is equal logically to the Other object,must be a Function.