Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: help

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Thanked 0 Times in 0 Posts

    Default help

    Create a class Polynomial that is used to evaluate a polynomial function of x:
    P(x) = a0 + a1x + a2x2 +!+ an"1xn"1 + anxn . The coefficients ai are floating-point numbers,
    the exponents of x are integers, and the largest exponent n—called the degree of the
    polynomial—is greater than or equal to zero. The class has the attributes
    • degree—the value of the largest exponent n
    • coefficients—an array of the coefficients ai
    and the following methods:
    • Polynomial(max)—a constructor that creates a polynomial of degree max whose
    coefficients are all zero
    • setConstant(i, value)—sets the coefficient ai to value
    • evaluate(x)—returns the value of the polynomial for the given value x
    For example, the polynomial
    P(x) = 3 + 5 x + 2 x3 is of degree 3 and has coefficients a0 = 3, a1 = 5, a2 = 0, and a3 = 2.
    The invocation:
    evaluate(7) computes
    3+ 5 " 7 + 0 " 72 + 2 " 73 = 3+ 35 + 0 + 686 = 724 and returns
    the result 724. A possible dialogue between the program and the user follows:
    Constructing a polynomial:
    3+ 5x + 2x^3
    Evaluating the polynomial at 0 should give 3
    Got: 3.0
    Evaluating the polynomial at 1 should give 10
    Got: 10.0
    Evaluating the polynomial at 7 should give 724
    Got: 724.0
    Evaluating the polynomial at 1/2 should give 5.75

  2. #2
    Moderators helloworld922's Avatar
    Join Date
    Jun 2009
    Thanked 619 Times in 561 Posts
    Blog Entries

    Default Re: help

    Could you please post what code/thoughts you have so far? Also, some insight into any problems/questions you're having would be nice.