Write java codes for the following LinkedList base program: The program should h
ID: 3564968 • Letter: W
Question
Write java codes for the following LinkedList base program:
The program should have following three classes:
Node.java , Polynomial.java, Project1.java
A one-variable polynomial of degree n is an arithmetic expression of the form:
a0+a1 x+a2 x^2+..........+an x^n
where a0 a1,a2, ......, an are the coefficients. Design and implement a class named Polynomial that uses a singly-linked list to store the coefficients (so there is virtually no limit on n ). Include a method that adds two polynomials and another method that multiplies two polynomials. For example, the following two polynomials
2 + x^2 - 3x^3 and 1 - x - 2x^2 + 3x^3
are represented by 2, 0, 1, -3 and 1, -1, -2, 3, respectively. The sum of these two polynomials is
3 - x - x^2
which is represented by 3, -1, -1; and the product of the two polynomials is
2 - 2x - 3x^2 + 2x^3 + x^4 + 9x^5 - 9x^6
which is represented by 2, -2, -3, 2, 1, 9, -9.
Note that you must write your code to maintain and manipulate the linked list data structure (i. e., do not use a utility library such as java.util.LinkedList). Email one week before the due date to get a data file to test your program. The data file will contain several pairs of polynomials. Each polynomial is given on a separate line (with coefficients separated by space instead of comma), and there is an empty line between two pairs. Your Java program should read and echo each pair of polynomials, compute and report their sum and product, and go on to process the next pair until the end of input. Specifically, the main method must look like:
while (not end of input) {
read and echo a pair of polynomials P1 and P2;
output sum (P1, P2); // Static method returning a polynomial
output product (P1, P2) // Static method returning a polynomial
}
Hand in a program listing with clear internal documentation and a printout of the results of execution using the test data file. Also email all JAVA program files (Node.java - the same as the one given in class except for the element field that becomes int type for this project, Polynoial.java, Project1.java) so your work can be easily recompiled and tested.
Data file will be like: coefficients of polynomials, not exact, just for as an example of
(The data file will contain several pairs of polynomials)
2 3 0 1 -3
1 -1 -2 3, 9
Output will be in same format with sum and product: coefficients of polynomials, not real, just for as an example.
5 -6 0 7 4
4 -2 -3 3, 7
sum: ...
product:...
...........
......etc
Explanation / Answer
OR
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.