Question: Using the attached files, Term.java, Polynomial.java, and PolynomialTester.java as starting points, writte a class Polynomial that stores a polynomial such as: p(x)=5x^10 + 9x^7 -
Using the attached files, Term.java, Polynomial.java, and PolynomialTester.java as starting points, writte a class Polynomial that stores a polynomial such as:
p(x)=5x^10 + 9x^7 - x - 10 as a linked list of terms. A term contains the coefficient and the power of x. For example, you would store p(x) as
(5,10),(9,7),(-1,1),(-10,0)
Supply methods to add, multiply, and print polynomials. Supply a constructor that makes a polynomial from a single term. For example, the polynomial p can be constructed as
Polynomial p = new Polynomial(new Term(-10, 0)); p.add(new Polynomial(new Term(-1, 1)); p.add(new Polynomial(new Term(9, 7)); p.add(new Polynomial(new Term(5, 10)); Then compute p(x) x p(x) Polynomial q = p.multiply(p); q.print();




** A class to represent an algebraic term. public class Term */ { private double coefficient; private int power; /** */ A constructor to initialize a single term with a given coefficient and power @param coefficent the coefficient @param power the power public Term(double coefficient, int power) { this.coefficient = coefficient; this.power = power; } /** * @return the coefficient public double getCoefficient() { return coefficient; } /** @return the power * public int getPower() { return power; } /** */ Multiplies two coefficient together and returns the result @param t the other term @return this * t as a term public Term multiply(Term t) { return new Term(coefficient * t.coefficient, power + t.power); } /** Adds the term to this term if the powers are the same */ @param t the term to attempt to add public void addIfSame Power (Term t) { if (t.power == power) { coefficient +=t.coefficient; } } /** */ Returns a string representation of the term with a ^ representing the exponent @return a string representation of a term public String toString() { if (power == 0) { return Math.abs (coefficient) + ""; } else if (power == 1) { return Math.abs (coefficient) + "x";
Step by Step Solution
3.43 Rating (159 Votes )
There are 3 Steps involved in it
Heres how you can solve the problem of connecting to a MySQL database from a Nodejs application and displaying actor information combining the insights from all four images 1 Install the MySQL Driver ... View full answer
Get step-by-step solutions from verified subject matter experts
