/** PolynomialD0.java defines a degree 0 polynomial. *  Author:  Joel C. Adams *  Version: For Java: An Introduction to Computing 1/e.  All Rights Reserved. */package ann.math.polynomial;import java.util.StringTokenizer;import ann.util.Controller;public class PolynomialD0 extends Object{ /** Default constructor  *  Postcondition: myA == 0.0.  */ public PolynomialD0() {   myA = 0.0; } /** Construct from double  *  Receive:       double aValue.  *  Postcondition: myA == aValue.  */ public PolynomialD0(double aValue) {   myA = aValue; } /** Construct from String  *  Receive:       StringBuffer polyString.  *  Precondition:  polyString is of the form "a",  *                   where a is a numeric value.  *  Postcondition: myA == a && a has been removed from polyString.  */ public PolynomialD0(String polyString) {   // myTokenizer = new StringTokenizer(polyString);   myBuffer = new StringBuffer(polyString);   myA = getNextCoefficient(); }  /** utility to extract coefficient from a polynomial string   *  Receive: int degree, the degree of the polynomial;   *            String polyString, the String containing the polynomial.   *  Return:  the coefficient for degree from within polyString.   */                     protected double getNextCoefficient() {   int start = 0;   boolean negative = false;   while (start < myBuffer.length()          && !Character.isDigit(myBuffer.charAt(start))          && myBuffer.charAt(start) != '.')   {     if (myBuffer.charAt(start) == '-')        negative = true;     start++;   }   int end = start + 1;   while (end < myBuffer.length()         && (Character.isDigit(myBuffer.charAt(end))             || myBuffer.charAt(end) == '.'             || myBuffer.charAt(end) == 'e'             || myBuffer.charAt(end) == 'E'))     end++;   double result = Double.parseDouble(myBuffer.substring(start,end));   myBuffer.delete(0, end+1);   if (negative)     return -result;   else     return result;  }    /** A-attribute accessor  *  Return: myA.  */ public double getA() {   return myA; } /** A-attribute mutator  *  Receive:       double newA.  *  Postcondition: myA == newA.  */ public void setA(double newA) {   myA = newA; } /** String converter (output)  *  Return: the String equivalent to myA.  */ public String toString() {   return Double.toString(myA); } //--- Attribute variable --- private double myA; private StringBuffer myBuffer;}