Question: please answer this in java also include comments. You will write four Java classes The Term Class Term represents a term in a polynomial. It
You will write four Java classes The Term Class Term represents a term in a polynomial. It will have two private instance variables (data fields) named coefficient and exponent. For example, 4x4 would be represented by a Term object with. coefficient 4 and exponent 6 . In terms of methods, this class necds - getters for each instance variable - a constructor that takes parameters for both instance variables - a toString that returns the Term in the forin: 4x16 - an addTerm method that takes a Term as a parameter and refurns a Term that is the sum of the calling object and the parameter If the sum of the two Terms cannot be expressed as a single Term (because the exponents don't match), it returns null The Polynomial Class Polynomial is the central class of your program, representing the actual polynomial expressions It will include the following elements: - A private inner class Node with two inatance variables termData of type Term and next of type Node. This class functions as the node class for the singly linked list representing your polymomial and should have the necessary functionality for that. - Two private instance variables of type Nodes termstead and terms Tail. These will be null if the polynomial has no terms. Otherwise, they will point to the first and last terms of the polynomial, respectively. - The following public methods: a default constructor A constructor that nccepts a String representing a polynomial in the form 4x6+ 2x3+1x2 and initializes the object to represent that polynomial. We are simplifying the problem by guarantecing spaces between tems and operators and explicitly representing coefficients of 1(50x2 is 1x2 rather than x22). Note that subtraction in the polynomial will result in a negative coefficient 3x2 - 2 will have two terms, one with coefficient 3 and exponent 2 and one with coefficient -2 and exponent 0 . There will be no negative exponents. an addTermToPolynomial that adds a Term to the end of the list of tems. a toString that returns a String representing the polynomial in the form shown in the sample output below. an addPolynomial that accepts a Rolynomial object as a parameter and returns a Polynomial object representing the sum of the calling object and the parameter. Your new polynomial must have the terms in the standard order (largest exponent to smallest) and must not include terms with coefficients of 0 . - You may add private methods as desired to imptove the design of the proggam. Vour fourth class will include main and will use the other classes to write a program that allows users to enter pairs of polynomials to be added
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
