Question: JAVA (Data Structures): Define a class QuadraticExpression that represents the quadratic expression ax^2 + bx + c: You should provide the following methods (1) default

JAVA (Data Structures):

Define a class QuadraticExpression that represents the quadratic expression ax^2 + bx + c:

You should provide the following methods

(1) default constructor which initalize all the coefficients to 0

(2) a constructor that takes three parameters

public QuadraticExpression(double a, double b, double c)

(3) a toString() method that returns the expression as a string.

(4) evaluate method that returns the value of the expression at x

public double evaluate(double x)

(5) set method of a, b, c

public void setA(double newA)

public void setB(double newB)

public void setC(double newC)

(6) public static QuadraticExpression sum( QuadraticExpression q1, QuadraticExpression q2):

returns a new expression that is the sum of the q1 and q2

(7) public static QuadraticExpression scale( double r, QuadraticExpression q)

returns a new expression that is r times q

(8) public int numberOfRoots()

returns number of roots, where 3 means infite number of roots

(9) public void add( QuadraticExpression q)

add q to the calling expression object

(10) public double smallerRoot() throws Exception

if no roots, throw exception

if single root, return it

if two roots, return the smaller root

if infinite root, return -Double.MAX_VALUE

(11) public double largerRoot() throws Exception

if no roots, throw exception

if single root, return it

if two roots, return the larger root

if infinite root, return Double.MAX_VALUE

(12) equals method

return true if two expressions have same a, same b and same c

(13) clone

return a copy of the calling object

(13) put your name at the top of your source file

/**

@author Your Name

*/

(14) use javadoc style comments for the class, and the methods

(15) test your class:

you can write your own main to test your code; but you have to pass the test in QuadraticExpressionTest.java

(16) use javadoc to generate document for your class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!