ex6 - Example 6: Polynomial with a Constructor /* class...

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

View Full Document Right Arrow Icon
Example 6: Polynomial with a Constructor /* class Polynomial * * Purpose: Show how to use a constructor and to use doubles (decimals) * */ public class Polynomial { private double toTheZeroth; // These are doubles, not ints private double toTheFirst; // They are private private double toTheSecond; // The mutators and accessors from last example public void setZeroth(double zero) { toTheZeroth = zero; } public void setFurst(double one) { toTheFirst = one; } public void setSecond(double two) { toTheSecond = two; } public double getZeroth() { return (toTheZeroth); } public double getFirst() { return (toTheFirst); } public double getSecond() { return (toTheSecond); } // This constructor initializes the variables to what the user // specified in their new call (see UsePolynomial code below) public Polynomial(double zero, double one, double two) { toTheZeroth = zero; toTheFirst = one; toTheSecond = two; } // print out in polynomial form public void print() { System.out.printf("%fx^2+%fx+%f",
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 / 2

ex6 - Example 6: Polynomial with a Constructor /* class...

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