Question: This is the source code I have so far. Im trying to get it to run. Please comment on what is doing what. In Class

This is the source code I have so far. Im trying to get it to run.

Please comment on what is doing what.

In Class Programming Assignment 9: Quadratic Equation C201 Fall 2017 Problem Description: 9.10 (Algebra: quadratic equations) Design a class named QuadraticEquation for a quadratic equation ax2+bx+x=0. The class contains: Private data fields a , b , and c that represent three coefficients. A constructor for the arguments for a , b , and c . Three getter methods for a , b , and c . A method named getDiscriminant() that returns the discriminant, which is b24ac. The methods named getRoot1() and getRoot2() for returning two roots of the equation These methods are useful only if the discriminant is nonnegative. Let these methods return 0 if the discriminant is negative. Write a test program that prompts the user to enter values for a, b, and c and displays the result based on the discriminant. If the discriminant is positive, display the two roots. If the discriminant is 0, display the one root. Otherwise, display The equation has no roots. See Programming Exercise 3.1 for sample runs.

This is the source code I have so far. Im trying to

QuadraticEquation class

/*

* Programmer:

* Date: 10/12/2017

* Purpose: Implement solution to exercise 9.1

0 from the Liang textbook.

*/

package testquadraticequation;

/**

*

*

*/

public class QuadraticEquation {

private double a;

private double b;

private double c;

QuadraticEquation(double a, double b, double c) {

this.a = a;

this.b = b;

this.c = c;

}//end constructor

public double getA() {

return a;

}

public double getB() {

return b;

}

public double getC() {

return c;

}

public double getDiscriminant() {

return Math.pow(b, 2.0)

-

4*a*c;

}

public double getRoot1() {

return ((

-

b)+Math.sqrt(this.getDiscriminant()))/(2*a);

}

public double getRoot2() {

return ((

-

b)

-

Math.sqrt

(this.getDiscriminant()))/(2*a);

}

}

In Class Programming Assignment 9: Quadratic Equation

TestQuadraticEquation class

/*

* Programmer:

* Date: 10/12/2017

* Purpose: Implement solution to exercise 9.10 from the Liang textbook.

*/

package testquadraticequation;

import java.util.Scanner;

/**

*

* @

*/

public class TestQuadraticEquation {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

// TODO code application logic here

double a, b, c;

Scanner inp

ut = new Scanner(System.in);

System.out.println("This program solves the quadratic equation.");

System.out.print("Enter a value for a: ");

a = input.nextDouble();

System.out.print("Enter a value for b: ");

b = input.

nextDouble();

System.out.print("Enter a value for c: ");

c = input.nextDouble();

QuadraticEquation e1 = new QuadraticEquation(a,b,c);

if(e1.getDiscriminant() == 0)

System.out.printf("This equation has only one s

olution, which is

%3.2f

\

n", e1.getRoot1());

else if(e1.getDiscriminant()

System.out.println("This equation has no real solutions.

\

n");

else

System.out.printf("Here are the two roots: %3.2f and %3.2f

\

n",

e1.getRo

ot1(), e1.getRoot2());

System.out.printf("The discriminant is %3.2f

\

n",

e1.getDiscriminant());

}

}

output-TestQuadraticEquation (run) ram solves the quadratie equation Enter a value for a: 1 Enter a value tor b: 2 Enter a value for c:1 This equation has only one solution, which is -1.00 The discriminant is 0.00 BUILD SUCCESSFUL (total time: 9 seconds)

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!