Question
Intro to java programming, problem 9.10 Algebra Quadratic Equations, the bold is where I am getting my errors package javaapplication3; import java.util.Scanner; public class JavaApplication3
Intro to java programming, problem 9.10 Algebra Quadratic Equations, the bold is where I am getting my errors
package javaapplication3; import java.util.Scanner;
public class JavaApplication3 {
/** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here //Problem 9.10 // UML diagram /******************************************************* * QuadraticEquation * -------------------------------------------------------- * -a: double * * -b: double * * -c: double * * +QuadradticEquation(a: double, b: double, c: double) * * +getA(): double * * +getB(): double * * +getC(): double * * +getDiscriminant(): double * * +getRoot1(): double * * +getRoot2(): double * *******************************************************/
Scanner input = new Scanner(System.in);
System.out.print("Enter a, b, c: "); double a = input.nextDouble(); double b = input.nextDouble(); double c = input.nextDouble();
QuadraticEquation quadraticEquation = new QuadraticEquation(a, b, c);
System.out.print("The equation has "); if (quadraticEquation.getDiscriminant() < 0) System.out.println("no real roots"); else if (quadraticEquation.getDiscriminant() > 0) { System.out.println("two roots " + quadraticEquation.getRoot1() + " and " + quadraticEquation.getRoot2()); } else { System.out.println("one root " + (quadraticEquation.getRoot1() > 0 ? quadraticEquation.getRoot1() : quadraticEquation.getRoot2())); } 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; }
public double getA() { return a; }
public double getB() { return b; }
public double getC() { return c; }
public double getDiscriminant() { return Math.pow(b, 2) - 4 * a * c; }
public double getRoot1() { return getDiscriminant() < 0 ? 0 : ((-b) + Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a); }
public double getRoot2() { return getDiscriminant() < 0 ? 0 : ((-b) - Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started