Following is the Java program to find the vertex, focus and directrix of a parabola −
Example
public class Demo{ public static void find_values(float val_1, float val_2, float val_3){ System.out.println("The value of vertex is (" + (-val_2 / (2 * val_1)) + ", "+ (((4 * val_1 * val_3) - (val_2 * val_2)) / (4 * val_1)) + ")"); System.out.println("The value of focus is (" + (-val_2 / (2 * val_1)) + ", " + (((4 * val_1 * val_3) - (val_2 * val_2) + 1) / (4 * val_1)) + ")"); System.out.println("The value of directrix is " + (int)(val_3 - ((val_2 * val_2) + 1) * 4 * val_1)); } public static void main(String[] args){ float val_1 = 6, val_2 = 2, val_3 = 9; find_values(val_1, val_2, val_3); } }
Output
The value of vertex is (-0.16666667, 8.833333) The value of focus is (-0.16666667, 8.875) The value of directrix is -111
A class named Demo contains a static function that takes in three float values. The formula for vertex, focus and directrix of parabola are substituted with values passed as parameter to the function. In the main unction, the values are defined, and the function is called on these values. The relevant data is displayed on the screen.