Poly - /* Choucri Philipp Bechir Assignment 1 Java Part*/...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
260345209 Assignment 1 Java Part*/ public class Poly { private float[] coefficients; public Poly() { coefficients = new float[1]; coefficients[0] = 0; } public Poly(int degree) { coefficients = new float[degree + 1]; for (int i = 0; i <= degree; i++) coefficients[i] = 0; } public Poly(float[] a) { coefficients = new float[a.length]; for (int i = 0; i < a.length; i++) coefficients[i] = a[i]; } public int getDegree() { return coefficients.length - 1; } public float getCoefficient(int i) { return coefficients[i]; } public void setCoefficient(int i, float value) { coefficients[i] = value; } public Poly add(Poly p) { int n = getDegree(); int m = p.getDegree(); Poly result = new Poly(Poly.max(n, m)); int i; for (i = 0; i <= Poly.min(n, m); i++) result.setCoefficient(i, coefficients[i] + p.getCoefficient(i)); if (i <= n) { // we have to copy the remaining coefficients from this object for (; i <= n; i++) result.setCoefficient(i, coefficients[i]); } else { // we have to copy the remaining coefficients from p for (; i <= m; i++)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

Poly - /* Choucri Philipp Bechir Assignment 1 Java Part*/...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online