[Solved] Node Represents Term Polynomial Eg 42x 3 2x 2 1 Would 1st Node Deg 3 Coeff 42 2nd Node Deg Q37199734
Each “Node” represents a term in a polynomial for eg = 4.2x^3 -2x^2 + 1 would be:
1st Node : deg = 3, coeff = 4.2
2nd Node : deg = 2, coeff = -2
3rd Node : deg = 0, coeff = 1
With this Knowledge and with the constructors given, writemethods that answer the Pre, Post and And statements for eachmethod.
class PNode {
// Basic node
int deg; // The degree of a term
float coeff; // The coefficient of a term
PNode next;
PNode (int d, float c) { //Constructor: builds a node with given data
next= null;
deg= d;
coeff= c;
}
PNode (int d, float c, PNoden){ // Constructor: builds a node with given reference
next = n;
deg= d;
coeff= c;
}
// Basic node operations
void scale(float k) { //scales coeff by k
coeff= coeff*k;
}
void multiplyByX(int d) { //increases the degree by d
deg= deg + d;
}
boolean simplified(PNode p) {//TODO
// PRE: p is the first node of a list of PNodes.
// POST: Returns true iff the nodes are sorted (descending)according to their degree field
// AND all nodes have distinct deg fields (no repeats)
// AND all nodes have a non-zero coefficient field.
return false;
}
PNode simplify(PNode p) { //TODO
// PRE: p is the first node of a list of PNodes. All nodes inthe list are already
// Sorted descending according to their deg field
// POST: Rearranges the list so that it is simplified butequivalent to the original representation,
// i.e. ensures that each node has distinct deg field (by usingpolynomial arithmetic)
// AND removes any nodes with coeff field set to 0.
// The simplified representation must be mathematicallyequivalent (as a polynomial)
// to the original representation.
// Returns the first node of the now rearranged list
return null;
}
PNode priorityAdd(PNode p, int d,float c) { //TODO
// PRE: the given list p list is simplified (simplified returnsTRUE);
// POST: Creates a new PNode with the given data (deg = d,coeff=c) and adds it to the
// current list so that the result is also simplified.
// Returns the first node of the list with the new addition
return null;
}
}
class PolyList {
PNode first= null;
// Class invariant — an instance of PolyList must alwayssatisfy the condition:
// The list is empty OR
// (The list is not empty AND
// All nodes have distinct deg fields AND
// There are no nodes having coeff equal to 0 AND
// All nodes are ordered from first to last with decreasing degfield. )
PolyList(PNode p) { // Constructor that sets its first node tothe given PNode p.
first= p;
}
int getDegree() { //TODO
// Returns the largest degree in the list representation.
return 0;
}
float getConstant() {//TODO
// Returns the coefficient of the node with zero degree
return 0;
}
boolean isConstant() {//TODO
// Returns true iff the polynomial is constant (as afunction).
return false;
}
Sorry, the code will be required in Java Programminglanguage
Expert Answer
Answer to Each “Node” represents a term in a polynomial for eg = 4.2x^3 – 2x^2 + 1 would be: 1st Node : deg = 3, coeff = 4.2 2nd N… . . .
OR

