public Polynomial addPolynomials(Polynomial p2){
        Polynomial polySum = new Polynomial();
        
        int x, y;
        
        PolyNode tempNode1 = this.firstNode;
        PolyNode tempNode2 = p2.firstNode;
        
        while(tempNode1 != null && tempNode2 != null){
            if(tempNode1.getExponent() == tempNode2.getExponent()){
                x = tempNode1.getCoefficient() + tempNode2.getCoefficient();
                y = tempNode1.getExponent();
                tempNode1 = tempNode1.getNext();
                tempNode2 = tempNode2.getNext();
            }else if(tempNode1.getExponent() > tempNode2.getExponent()){
                x = tempNode1.getCoefficient();
                y = tempNode1.getExponent();
                tempNode1 = tempNode1.getNext();
            }else{
                x = tempNode2.getCoefficient();
                y = tempNode2.getExponent();
                tempNode2 = tempNode2.getNext();
            }
            polySum.addPolyNode(x, y);
        }
        
        while(tempNode1 != null){
            x = tempNode1.getCoefficient();
            y = tempNode1.getExponent();
            tempNode1 = tempNode1.getNext();
            polySum.addPolyNode(x, y);
        }
        
        while(tempNode2 != null){
            x = tempNode2.getCoefficient();
            y = tempNode2.getExponent();
            tempNode2 = tempNode2.getNext();
            polySum.addPolyNode(x, y);
        }
        return polySum;
    }