For the code below, please design a few JUnit tests for the implementation: Class 1: import java.util.Hashtable; public class Polynomial implements PolynomialInterface{ // using a hashtable to store the coefficient associated to the power // here power is the key while the coefficient is the value Hashtable terms; public Polynomial() { this.terms = new Hashtable<>(); } public void addTerm(int power, double coefficient) { if (power Class 2: public class PolynomialImpl { private class node { public int coeff; public int power; //we also need to store reference to next node as this is a linked list public node next; node(int Coeff, int Power) { coeff = Coeff; power = Power; next = null; } } //we need to create reference to first element of the list private node first; public PolynomialImpl() { /* * this is the empty polynomial; * i.e. polynomial with no terms; */ first = null; } private int get_pow_coeff(String t, boolean f) { /* * this function will extract the power and coefficient in the term t * boolean f tells whether we want to extract power(f=true) or coeff.(f=false) */ int power; int coeff; //t must be of the form: (+/-/ )x^ //we check if t contains &#39;+&#39; or &#39;-&#39; int i1 = t.indexOf(“+”); int i2 = t.indexOf(“-“); if (i1 == -1 && i2 == -1) { //this means that t is: x^ int i3 = t.indexOf(“x”); if (i3 == -1) { //this means that t is a constant term coeff = Integer.valueOf(t); power = 0; } else { //we now extract coeff. and power based on i3(index of “x”) coeff = Integer.valueOf(t.substring(0, i3)); power = Integer.valueOf(t.substring(i3 + 2)); //since i3+1 contains &#39;^&#39; } } else { //this means t is either: +x^ or -x^ //we ignore the case when &#39;+&#39; is present, however if &#39;-&#39; is present, we multiply the coeff by -1 int i3 = t.indexOf(“x”); if (i3 == -1) { //this means that t is a constant term coeff = Integer.valueOf(t.substring(1)); if (i2 != -1) coeff = -1 * coeff; power = 0; } else { //we now extract coeff. and power based on i3(index of “x”) coeff = Integer.valueOf(t.substring(1, i3)); if (i2 != -1) //i.e. &#39;-&#39; is present coeff = -1 * coeff; power = Integer.valueOf(t.substring(i3 + 2)); //since i3+1 contains &#39;^&#39; } } if (f) //power extraction return power; else return coeff; } public PolynomialImpl(String poly) { /* * this method parses the string, poly and accordingly updates the linked list * we assume that each term has a different power * we must store only the non-zero terms and in decreasing order of their powers * we use “+” as the connector connecting the terms in the list. * our strategy to parse the string is to first split it into tokens using space(” “) as delimiter * we then insert these tokens(terms) in the list using an insertion sort kind of algorithm, i.e. * we take each term and insert it into its correct(according to its power) position in the list. * our search is easy as we always maintain sorted(decreasing) order in the list */ String[] tokens = poly.split(” “); //we now insert the tokens in the list using insertion sort for (String t : tokens) { /* * we now iterate over the list searching for the correct position of term, t * since we don&#39;t have back references, it is important that we compare with the neighbour of the current element. * so that we can insert the new element in between if required. * we first check if last is null and if so, we just insert t as the list is empty. * however if list contains only one element, then its neighbour will be null and hence we need to handle this case * also when we reach the last element in the list while searching, this means that all elements in the list are bigger than t and hence its position is last * the last two cases above can be covered by a single condition in which we compare with the last element and accordingly insert. */ int power = get_pow_coeff(t, true); int coeff = get_pow_coeff(t, false); node temp = first; //our iterator over the list reference if (temp == null) { //i.e. no element present in the list //now we just create a new node and insert t in the list node n = new node(coeff, power); first = n; } else { //now we iterate over the sorted list searching for the correct position of t by comparing its power with other powers boolean flag = false; while ( != null) { int comp_power =; if (power > comp_power) { //i.e. we need to insert t here node n = new node(coeff, power); =; //we point t&#39;s next element to temp&#39;s neighbour = n; //we point temp to n since it is now in b/w temp and its old neighbour flag = true; //we update this flag to assert that we have inserted t break; //we exit the loop since we have inserted t } else { //we continue searching further down the list temp =; } } //now we insert t at the end if flag is false if (!flag) { int comp_power = temp.power; if (power > comp_power) { node n = new node(coeff, power); = temp; first = n; } else { node n = new node(coeff, power); = null; = n; } } } } }

"Get 15% discount on your first 3 orders with us"
Use the following coupon

Order Now