# Poly - Choucri Philipp Bechir Assignment 1 Java Part public...

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

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++)

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 10/02/2010 for the course COMP 250 taught by Professor Blanchette during the Spring '08 term at McGill.

### Page1 / 4

Poly - Choucri Philipp Bechir Assignment 1 Java Part public...

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

View Full Document
Ask a homework question - tutors are online