-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathQuadratic.java
More file actions
54 lines (44 loc) · 1.3 KB
/
Quadratic.java
File metadata and controls
54 lines (44 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
public class Quadratic {
private double a;
private double b;
private double c;
public static int numOfObjects = 0;
public Quadratic(int a, int b, int c) {
this.a = a;
this.b = b;
this.c = c;
numOfObjects++;
}
public Quadratic() {
a = 1;
b = 0;
c = 0;
numOfObjects++;
}
public static int numQuadratics() {
return numOfObjects;
}
public String toString() {
return "y = " + a + "x^2 + " + b + "x + " + c;
}
public String vertex() {
double x = -b / (2 * a);
double y = a * x * x + b * x + c;
return "The vertex is at (" + x + "," + y + ")";
}
public void quadraticFormula() {
if (b * b - (4 * a * c) < 0) {
System.out.println("No Solutions");
} else {
double x1 = (-b + Math.sqrt(b * b - (4 * a * c))) / (2 * a);
double x2 = (-b - Math.sqrt(b * b - (4 * a * c))) / (2 * a);
System.out.println("x = " + x1 + " and x = " + x2 + ".");
}
}
public boolean isOnQuadratic(Point p) {
if ((this.a * p.getX() * p.getX() + this.b * p.getX() + this.c) == p.getY()) {
return true;
}
return false;
}
}