Would using a special value of x (such as 0.0) as a sentinel work well in this program?

A good answer might be:

No—the user might want to see the value of the polynomial when x is 0.0, or any other value.

Testing the User's Response

In this program, no special number is suitable as a sentinel because any number is potential data. Because of this, There must be a separate prompt asking if the user wants to continue. For each iteration of the loop the user will be prompted for two things:

  1. Whether to continue, and
  2. A new value for x.

Here is an outline of the program:

class evalPoly
{
  public static void main (String[] args ) throws IOException
  {

    double x;                      // a value to use with the polynomial
    String response = "y";         // "y" or "n"

    while ( response.equals( "y" ) )    
    {
       // get a value for x

       // evaluate the polynomial

       // print out the result

       // ask the user if program should continue
       // the user's answer will be "response"
      
    }

  }
}

It is often useful to work on one aspect of a program at a time. So let us just look at the "user prompting and looping" aspect and temporarily ignore the polynomial evaluation aspect. This will involve using objects of type String.

The condition part of the while statement, response.equals("y") evaluates to true or false. Here is how this happens:

In other words, the condition response.equals( "y" ) asks: did the user type a "y"?

QUESTION 15:

The program will be doing input and output. Which of the Java packages should be imported?