# gPol Class

Step 1: problem domain

Main goal of this class is to help users to work with polynomials. Definition of polynomials are here: http://en.wikipedia.org/wiki/Polynomial

Users should be able to define objects from gPol class. Then set their polynomials and perform mathematics operations on them.

gPol works with Java standard numbers (not Big Numbers !).

Step 2: Public Interface

2-1- Constructor Methods

```public gPol(); // set to 0
public gPol(String p);  // gPol x=new gPol("-2*x^3-4.2+x");
public gPol(gPol p);```

2-2- Setter Methods

```public void Set(String p);
public void Set(gPol p);
public void SetCoefficient(int index, double c);
// to set Polynomial Coefficients to specific place```

2-3- Getter Methods

```public double toArray(); // to get array of Polynimial
public double getCoefficient(int index);
public int MaxPow(); // return max power of x that exist in polynomial```

2-4- Functionalities of class (Methods)

```// this=a+b;
public void SetSum(gPol a, gPol b);

// this=a-b;
public void SetMinus(gPol a, gPol b);

// this=a*b;
public void SetMultiple(gPol a, gPol b);

// this=a/b;
public void SetDiv(gPol a, gPol b);

// this=a%b;
public void SetMod(gPol a, gPol b);

// derive x^2 is 2*x
public void SetDerive(); //calc Derive of this and set to this
public void SetDerive(gPol a); //calc Derive of a and set to this

public void SetAntegral(); //calc Antegral of this and set to this
public void SetAntegral(gPol a); //calc Antegral of a and set to this```

2-5- Standard Library Methods overloading (such as toString, equals,…)

```public String toString();
public int compareTo(gPol a);
public boolean equals(Object anObject);
public int hashCode();
public gPol clone();```

Step 3: private variables

Private variables of this class may be implemented by two ways:

1- use an array of double type to save polynomial coefficients and an int variable to length of it. (for example -3.1*x^5 affects A=-3.1;)

2- use a linked list to save term of given polynomial.

At the first step, students should implement gPol with first way. In second step, after teaching LinkedLists , students should implement it with second way.

Step 4: implementing main classes

Students work !

Step 5: useful application

gPolCALC project is applications of this class.