1 / 14

E&CE 250: Project 2 PolynomialAsArray

E&CE 250: Project 2 PolynomialAsArray. Michael Jarrett msjarret@uwaterloo.ca. http://www.eng.uwaterloo.ca/~msjarret/ece250/Project2.ppt. Overview. Create a PolynomialAsArray class to represent a polynomial function. Information about this polynomial is stored in an array of doubles.

Download Presentation

E&CE 250: Project 2 PolynomialAsArray

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. E&CE 250: Project 2PolynomialAsArray Michael Jarrett msjarret@uwaterloo.ca http://www.eng.uwaterloo.ca/~msjarret/ece250/Project2.ppt

  2. Overview • Create a PolynomialAsArray class to represent a polynomial function. • Information about this polynomial is stored in an array of doubles. P(x) = anxn + an-1xn-1 + ... + a2x2 + a1x + a0 ECE250 Project2 Oct. 2nd, 2003

  3. Requirements of Interface • Your PolynomialAsArray class must implement the Polynomial interface shown below. • You must include Polynomial.java in your project, EXACTLY as shown in the project description. Polynomial.java public interface Polynomial { int getDegree (); double getCoefficient (int i); void setCoefficient (int i, double c); void assign (Polynomial p); Polynomial plus (Polynomial p); Polynomial minus (Polynomial p); Polynomial times (Polynomial p); double eval (double x); Polynomial getDerivative (); String toString(); } ECE250 Project2 Oct. 2nd, 2003

  4. Distilled from project description Methods • Polynomial() • You must provide this constructor; create P(x)=0. • double getCoefficient (int i) • Return 0 when i > degree • Consider the case of i < 0 • void assign (Polynomial p) • Makes this polynomial have the same coefficients as p. • Make sure both polynomials can later be changed independently. ECE250 Project2 Oct. 2nd, 2003

  5. Distilled from project description Methods (2) • int getDegree() • Polynomial getDerivative () • Return polynomial represention (d/dx) of current polynomial. • String toString () • eg. 10x^3 – 2x + 3 • Special case: print 0 if P(x) = 0 • Must start with highest-degree term. • Must only contain non-zero terms. ECE250 Project2 Oct. 2nd, 2003

  6. Distilled from project description Methods (3) • Polynomial plus (Polynomial p) • return this + p • Polynomial minus (Polynomial p) • return this - p • Polynomial times (Polynomial p) • return this * p • double eval (double x) • Evaluate polynomial at x; consider running time of algorithm you choose to do this. ECE250 Project2 Oct. 2nd, 2003

  7. Distilled from project description Methods (4) • void setCoefficient (int i, double c) • If degree of polynomial changes, you must resize your array to be length degree+1. • Resize the array by creating a new array, and copying the contents of the old one. • Consider: c == 0 • Consider: i > degree Note: System.arraycopy(Object src, int srcOffset, Object dest, int destOffset, int length); ECE250 Project2 Oct. 2nd, 2003

  8. Distilled from project description Rules • Your class must not be in a package. • You cannot modify interface Polynomial. • You may add members to your PolynomialAsArray class. • Implementation must use an array of doubles. • Length of array must always be equal to the degree of the polynomial plus one. ECE250 Project2 Oct. 2nd, 2003

  9. Distilled from project description Marking Criteria • Correctness according to project description. • Handling of error conditions. • Correct resizing of polynomial. • Execution speed. • Pay careful attention to asymptotic running time as the degree gets large. • Code quality metrics. • Your code needs to have meaningful comments. ECE250 Project2 Oct. 2nd, 2003

  10. Demo Program • We provide class Demo on the website. • This class will generate the output you must include with your submission. • Run as “java Demo PolynomialAsArray”. • Please include Demo.java in your jar file (you may not modify this file). • We will use the same class to test project 3! ECE250 Project2 Oct. 2nd, 2003

  11. How Demo Works • Asks the Java Virtual Machine to load a class by name. • And then uses reflection to create a new PolynomialAsArray from the class object. • We then can run tests on the object using the methods of the Polynomial interface. Class clazz = Class.forName (className); Polynomial p = (Polynomial) clazz.newInstance (); ECE250 Project2 Oct. 2nd, 2003

  12. Some Possible Errors • Not resizing array when needed. • Not checking for illegal arguments. • toString output not in correct form. • Too much or too little commented code. • Assuming you are being passed a PolynomialAsArray when the interface only specifies a Polynomial. ECE250 Project2 Oct. 2nd, 2003

  13. Submission: Due Oct 16th, 6:00pm • Create a .jar file containing: • .java source files with author id & Demo file • .class files & Demo.class • submission form • outp2.txt • Verify that .jar file will execute directly on the Sun Java 2 SDK platform prior to submission: java –jar xxxxxxxxp2.jar PolynomialAsArray • Submit your .jar file to CourseBook. ECE250 Project2 Oct. 2nd, 2003

  14. How to get help • msjarret@uwaterloo.ca • Newsgroup: uw.ece.ece250 • Office hour: Every Tuesday, 12:30-1:30 in E2-2365. ECE250 Project2 Oct. 2nd, 2003

More Related