/home/caleb/ASDV-Java/Semester 2/Assignments/lab2_CalebFontenot/src/main/java/com/calebfontenot/lab5_calebfontenot/QuadraticEquation.java |
nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt
nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java
package com.calebfontenot.lab5_calebfontenot;
@author
public class QuadraticEquation {
private double a;
private double b;
private double c;
public QuadraticEquation(double a, double b, double c)
{
this.a = a;
this.b = b;
this.c = c;
}
public double getDiscriminant()
{
return b * b - 4 * a * c;
}
public double getRoot1()
{
if (getDiscriminant() < 0) {
return -88888888;
}
return (b + Math.sqrt(b * b - 4 * a * c)) / (2 * a);
}
public double getRoot2()
{
if (getDiscriminant() < 0) {
return -88888888;
}
return (-b + Math.sqrt(b * b - 4 * a * c)) / (2 * a);
}
@Override
public String toString()
{
return "QuadraticEquation{" + "a=" + a + ", b=" + b + ", c=" + c + '}';
}
@return
public double getB()
{
return b;
}
@return
public double getC()
{
return c;
}
@return
public double getA()
{
return a;
}
public static void main(String[] args)
{
QuadraticEquation eq1 = new QuadraticEquation(1, -4, 4);
System.out.println(eq1);
System.out.println(eq1.getRoot1());
System.out.println(eq1.getRoot2());
}
}