Created
January 13, 2010 01:43
-
-
Save johnhmj/275841 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
class Quadratic { | |
private PrintStream jout = new PrintStream(System.out); | |
private double a, b, c, delta; | |
private CComplex x1 = new CComplex(); | |
private CComplex x2 = new CComplex(); | |
public Quadratic() { | |
this.a = 0; | |
this.b = 0; | |
this.c = 0; | |
this.delta = 0; | |
} | |
public void Solution() | |
{ | |
this.delta = Math.pow(this.b, 2.0) - 4 * this.a * this.c; | |
if ( this.delta > 0 ) | |
{ | |
this.x1.real = ((0.0 - this.b) + Math.sqrt(this.delta)) / this.a; | |
this.x2.real = ((0.0 - this.b) - Math.sqrt(this.delta)) / this.a; | |
} | |
else if ( this.delta < 0 ) | |
{ | |
this.x1.real = (0.0 - this.b) / this.a; | |
this.x2.real = this.x1.real; | |
this.x1.imaginary = Math.sqrt((0 - this.delta)) / this.a; | |
this.x2.imaginary = 0 - this.x1.imaginary; | |
} | |
else | |
{ | |
this.x1.real = (0.0 - this.b) / this.a; | |
this.x2.real = this.x1.real; | |
} | |
} | |
public void setA(double x) | |
{ | |
this.a = x; | |
} | |
public void setB(double x) | |
{ | |
this.b = x; | |
} | |
public void setC(double x) | |
{ | |
this.c = x; | |
} | |
public CComplex getX1() | |
{ | |
return this.x1; | |
} | |
public CComplex getX2() | |
{ | |
return this.x2; | |
} | |
public void Readme() | |
{ | |
jout.printf("Compute x of formula\n"); | |
jout.printf("ax^2 + bx + c = 0\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment