A one-variable quadratic expression is an arithmetic expression of the form , where ax 2 , bx,

Question:

A one-variable quadratic expression is an arithmetic expression of the form , where ax2, bx, and c are some fixed numbers (called the coefficients) and x is a variable that can take on different values. Specify, design, and implement a class that can store information about a quadratic expression. The constructor should set all three coefficients to zero, and another method should allow you to change these coefficients. There should be accessor methods to retrieve the current values of the coefficients. There should also be a method to allow you to “evaluate” the quadratic expression at a particular value of x (i.e., the method has one parameter x and returns the value of the expression ax2 + bx + c).

Also write the following static methods to perform these indicated operations:

public static Quadratic sum(
Quadratic q1,
Quadratic q2
)
// Postcondition: The return value is the
// quadratic expression obtained by adding
// q1 and q2. For example, the c coefficient
// of the return value is the sum of q1’s c
// coefficient and q2’s c coefficient.
public static Quadratic scale(
double r,
Quadratic q
)
// Postcondition: The return value is the
// quadratic expression obtained by
// multiplying each of q’s
// coefficients by the number r.

The first argument of the scale method is a double number (rather than a quadratic expression). For example, this allows the method activation Quadratic.scale(3.14, q) where q is a quadratic expression.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: