0

hi..

we really need help on how to d i s p l a y, a d d, s u b t r a c t,
m u l t i p l y polynomials.

the display should be in ascending order of degree..

and our program should be j a v a desktop application..

and also we suppose to have a p o l y n o m i a l .java
where it serves as our main class.

please help.. even just algorithms for the above function will be helpful.

thank you in advance. :)

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by NormR1
0

You forgot to post the code you are having problems with along with specific questions about that code.
Waiting for your code...

0

here are my codes in the attachments..
and my prob is how to create the code for
the empty methods in my attachments.

it's about p o l y n o m i a l s
where u have 2 equations
then you supposed to add, subtract or multiply them
and lastly display the final answer
in descending order...

thank you.

Attachments design.png 16.47 KB
private void addActionPerformed(java.awt.event.ActionEvent evt) {                                    
        // TODO add your handling code here:
    }                                   

    private void subtractActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
    }                                        

    private void multiplyActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
    }                                        

    private void coefActionPerformed(java.awt.event.ActionEvent evt) {
	// TODO add your handling code here:
    }

    private void degActionPerformed(java.awt.event.ActionEvent evt) {
	// TODO add your handling code here:
    }

    private void P1ActionPerformed(java.awt.event.ActionEvent evt) {
	// TODO add your handling code here:
    }

    private void P2ActionPerformed(java.awt.event.ActionEvent evt) {
	// TODO add your handling code here:
    }
public class Polynomial <T>
{

    private Node firstNode;
    private int length;

    public final void clear()
    {
	Node newNode = new Node(0,-1);
	firstNode = newNode;
	firstNode.next = firstNode;
	length = 0;
    }

    public boolean add(int newCoef, int newDeg)
    {
	Node newNode = new Node(newCoef, newDeg);
	if (isEmpty())
	  firstNode = newNode;
	else
	{
	Node lastNode = getNodeAt(length);
	lastNode.next = newNode;
	}
	length++;
	return true;
    } // end add

    public boolean add(int newPosition, int newCoef, int newDeg)
    {
      boolean isSuccessful = true;

      if ((newPosition >= 1) && (newPosition <= length+1))
      {
        Node newNode = new Node(newCoef, newDeg);
        if (isEmpty() || (newPosition == 1))  // case 1
        {
          newNode.next = firstNode;
          firstNode = newNode;
        }
        else // case 2: newPosition >1, list is not empty
        {
          Node nodeBefore = getNodeAt(newPosition - 1);
          Node nodeAfter = nodeBefore.next;
          newNode.next = nodeAfter;
          nodeBefore.next = newNode;
        } // end if
        length++;
      }
      else
        isSuccessful = false;
      return isSuccessful;
  } // end add

    public void remove(int givenPosition)
    {
      Node result = firstNode.next;

      if (!isEmpty() && (givenPosition >= 1) && (givenPosition <= length))
      {
        assert !isEmpty();
        if (givenPosition == 1)
        {
          firstNode = result.next;
        }
        else
        {
          Node nodeBefore = getNodeAt(givenPosition-1);
          Node nodeToRemove = nodeBefore.next;
          Node nodeAfter = nodeToRemove.next;
          nodeBefore.next = nodeAfter; // disconnect node to be removed
        } // end if
        length--;
      } // end if
    } // end remove

    public int getCoef(int givenPosition)
    {
      int result = 0; // result to return

      if ((givenPosition >= 1) && (givenPosition <= length))
      {
          assert !isEmpty();
          result = getNodeAt(givenPosition).coef;
      }
      return result;
    } // end getEntry

    public int getDeg(int givenPosition)
    {
      int result = 0; // result to return

      if ((givenPosition >= 1) && (givenPosition <= length))
      {
          assert !isEmpty();
          result = getNodeAt(givenPosition).deg;
      }
      return result;
    } // end getEntry




    public int getLength()
    {
      return length;
    }

    public boolean isEmpty()
    {
      boolean result;
      if(length == 0)
      {
        assert firstNode == null;
        result = true;
      }
      else
      {
        assert firstNode != null;
        result = false;
      } // end if

      return result;

    }

    public boolean isFull()
    {
      return false;
    }


    private Node getNodeAt(int givenPosition)
    {
      Node currentNode = firstNode;

      // traverse the list to locate the desired node
      for (int counter = 1; counter < givenPosition; counter++)
        currentNode = currentNode.next;

      return currentNode;
    } // end getNodeAt

    public Polynomial()
    {
	clear();
    }

    public Polynomial DisplayPolynomial()
    {
	 
    }

    public Polynomial AddPolynomials(Polynomial p1, Polynomial p2)
    {
    }

    public Polynomial SubractPolynomials(Polynomial p1, Polynomial p2)
    {
    }

    public Polynomial MultiplyPolynomials(Polynomial p1, Polynomial p2)
    {
    }

    private class Node
    {
      private int coef;
      private int deg;
      private Node next;

      private Node(int dataPortion1, int dataPortion2)
      {
        coef = dataPortion1;
	deg = dataPortion2;
        next = null;
      } // end constructor

      private Node(int dataPortion1, int dataPortion2, Node nextNode)
      {
        coef = dataPortion1;
	deg = dataPortion2;
        next = nextNode;
      } // end constructor

      private void setData(int dataPortion1, int dataPortion2)
      {
	  coef = dataPortion1;
	  deg = dataPortion2;
      } // end setData

      private int getCoef()
      {
        return coef;
      } // end getData

      private int getDeg()
      {
        return deg;
      } // end getData

      private void setNextNode(Node nextNode)
      {
        next = nextNode;
      } // end setNextNode

      private Node getNextNode()
      {
        return next;
      } // end getNextNode

    } // end Node
}
0

The desktop app code is an empty skeleton that you need to fill in.

The other file has 4 compile errors in it.

Please fix both the java source files so that they will compile or if you have problems, please copy and paste here the full text of the error messages along with the full source that has the errors.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.