Cubic.java - public class Cubic cfw double x double a b c d...

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

View Full Document Right Arrow Icon
public class Cubic { double x; double a, b, c, d; public Cubic(double a1, double b1, double c1, double d1){ a = a1; b = b1; c = c1; d = d1; } public Cubic (double b1, double c1, double d1){ a = 0; b = b1; c = c1; d = d1; } public double eval(double x){ return a*x*x*x+b*x*x+c*x+d; } public Cubic add(Cubic n2){ // return new Cubic(a + n2.a, b + n2. b, c + n2.c, d + n2.d); Cubic x1 = new Cubic(0,0,0,0); this.a = a + n2.a; this.b = b + n2.b; this.c = c + n2.c; this.d = d + n2.d; return x1; } public Cubic neg(){ Cubic n3 = new Cubic(0,0,0); n3.a = -a; n3.b = -b; n3.c = -c; n3.d = -d; return n3; // return new Cubic(-a, -b, -c, -d); } public String toString(){ String res = ""; res = addElement(res, a, 3); res = addElement(res, b, 2);
Image of page 1

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern