ComplexFunction Class - Shir-Av/Ex1 GitHub Wiki
ComplexFunction class implements complex_function interface. represents a complex function of type y=g(f1(x), f2(x)), where both f1, f2 are functions (or complex functions), y and x are real numbers and g is an operation: plus, mul, div, max, min, comp (f1(f2(x))). for example: "plus(mul(2x,-4+5x-x^5),3.2x)".
This object is buils of :
- public Operation op;
- public function left
- public function right;
Constructors and methods implemented:
- public ComplexFunction(): defult constractor set operation = none, left = null, right = null
- public ComplexFunction(Operation op, function f1, function f2): constractor set values: operation = op, left = f1, right = fs.
- public ComplexFunction(function cf): constractor that recives only 1 function, set operation = none, left = f1, right = null.
- public ComplexFunction(String op, function f1, function f2): constractor that recives the operation as a string, set operation = op, left = f1, right = null.
- public void plus(function f1): "plus" = add. creats a new complex function with operation = plus, left = this, right = f1.
- public void mul(function f1): "mul" = multiply. creats a new complex function with operation = mul, left = this, right = f1.
- public void div(function f1): "div" = divide. creats a new complex function with operation = div, left = this, right = f1.
- public void max(function f1): "max" = returns the maximum between 2 objects. creats a new complex function with operation = max, left = this, right = f1.
- public void min(function f1): "min" = returns the minimum between 2 objects. creats a new complex function with operation = min, left = this, right = f1.
- public void comp(function f1): "comp" = returns f(g(x)). creats a new complex function with operation = comp, left = this, right = f1.
- public boolean equals(Object obj): Returns true if and only if this.f(x) equals to obj.f(x) in a set range.
- public String toString(): Print the function as: "op(func1,func2)".
- public double f(double x): returns the f(x) value of this complex function.
- public function initFromString(String s): return a new ComplexFunction by using initFromString recursively and using the "middle" and "basicFormat" methods.
- public int middle(String s): split the string in a format of "string(operation)(string(f1), string(f2))" by checking the parenthsis and commas.
- public boolean basicFormat(String s): checks the format of the givan string. returns true if the open Parenthesis equals the close Parenthesis and if comma is smaller than the Parenthesis. else returns false.