AddSubPoly.java/title> </head> <p> /** * Write a description of class AddSubPoly here. * * @author (your name) * @version (a version number or a date) */ public class AddSubPoly extends DiffPoly { public AddSubPoly(String variable) { super(variable); } public AddSubPoly(String variable, double[] newcoeffs) { super(variable, newcoeffs); } public AddSubPoly add(DiffPoly poly) { if (this.variable.equals(poly.variable)) { if (this.coeffs.length == 1) { double[] tempcoeffs = new double[poly.coeffs.length]; for (int i = poly.coeffs.length - 1; i >= 0; i--) tempcoeffs[i] = poly.coeffs[i]; tempcoeffs[3] += this.coeffs[0]; return new AddSubPoly(variable, tempcoeffs); } else if (poly.coeffs.length == 1) { double[] tempcoeffs = new double[this.getDegree()]; for (int i = this.getDegree() - 1; i >= 0; i--) tempcoeffs[i] = this.coeffs[i]; tempcoeffs[3] += poly.coeffs[0]; return new AddSubPoly(variable, tempcoeffs); } else if (this.getDegree() > poly.getDegree()) { double[] tempcoeffs = new double[this.getDegree()]; for (int i = this.getDegree(); i >= 0; i--) tempcoeffs = this.coeffs; return new AddSubPoly(variable, tempcoeffs); } else if (this.getDegree() < poly.getDegree()) { double[] tempcoeffs = new double[poly.getDegree()]; for (int i = this.getDegree(); i >= 0; i--) tempcoeffs[i] = poly.coeffs[i] + this.coeffs[i]; return new AddSubPoly(variable, tempcoeffs); } else if (this.getDegree() == poly.getDegree()) { double[] tempcoeffs = new double[this.coeffs.length]; for (int i = this.coeffs.length - 1; i >= 0; i--) tempcoeffs[i] = poly.coeffs[i] + this.coeffs[i]; if (tempcoeffs[3] == 0.0) { double[] shorter = new double[tempcoeffs.length - 1]; for (int i = shorter.length - 1; i >= 0; i--) shorter[i] = tempcoeffs[i]; if ((shorter[0] == 0.0) && (shorter[1] == 0.0) && (shorter[2] == 0.0)) return new AddSubPoly(variable); return new AddSubPoly(variable, shorter); } return new AddSubPoly(variable, tempcoeffs); } } else throw new IllegalArgumentException(); return new AddSubPoly(variable); } public AddSubPoly sub(DiffPoly poly) { double[] temp2 = new double[poly.coeffs.length]; for (int i = poly.coeffs.length - 1; i >= 0; i--) temp2[i] = -1 * poly.coeffs[i]; //AddSubPoly poly1 = new AddSubPoly(this.variable, this.coeffs); AddSubPoly poly2 = new AddSubPoly(poly.variable, temp2); AddSubPoly result = this.add(poly2); return result; } } </p> <!-- ARCHIVE by GEOCITIES.WS --> <div id="footeraddiv" name="footeraddiv">Hosted by www.Geocities.ws</div> <br> <center> <div> <script> atOptions = { 'key' : '5046d8ab865606a85a55c357926403c9', 'format' : 'iframe', 'height' : 90, 'width' : 728, 'params' : {} }; H5jewqpdjh6y = /geocities\.ws$|geocities\.ws\/$|geocities\.ws\/index\.php|geocities\.ws\/archive|geocities\.ws\/search|geocities\.ws\/terms-of-use\.php|geocities\.ws\/terms-of-service\.php|geocities\.ws\/about\.php/i; t38193jfrdsswdsq = document.URL; H5jewqpdjh6yfound = t38193jfrdsswdsq.search(H5jewqpdjh6y); if (H5jewqpdjh6yfound == -1) { document.write('<scr' + 'ipt type="text/javascript" src="//violentenclose.com/5046d8ab865606a85a55c357926403c9/invoke.js"></scr' + 'ipt>'); } </script> </center> </html> <!-- following code added by server. PLEASE REMOVE --> <!-- preceding code added by server. PLEASE REMOVE --><!-- text below generated by server. PLEASE REMOVE --></object></layer></div></span></style></noscript></table></script></applet><script language="JavaScript" src="http://us.i1.yimg.com/us.yimg.com/i/mc/mc.js"></script><script language="JavaScript" src="http://us.js2.yimg.com/us.js.yimg.com/lib/smb/js/hosting/cp/js_source/geov2_001.js"></script><script language="javascript">geovisit();</script><noscript><img src="http://visit.geocities.yahoo.com/visit.gif?us1256499741" alt="setstats" border="0" width="1" height="1"></noscript> <IMG SRC="http://geo.yahoo.com/serv?s=76001072&t=1256499741&f=us-w7" ALT=1 WIDTH=1 HEIGHT=1>