Java Program to Find the Vertex, Focus, Directrix of a Parabola

bookmark

class Main
{
    public static void main(String[] args)
    {
        //value of a, b, c declared
        double a = 4;
        double b = 2;
        double c = 1;
        //finding vertex
        System.out.println("Vertex: (" + (-b / (2 * a)) + ", " + (((4 * a * c) - (b * b)) / (4 * a)) + ")"); 
        //finding focus
        System.out.println("Focus: (" +  (-b / (2 * a)) + ", " + (((4 * a * c) - (b * b) + 1) / (4 * a)) + ")"); 
        //finding directrix
        System.out.println("Directrix:" + " y= " + (int)(c - ((b * b) + 1) *  4 * a)); 
    }
}

 


Output:

Vertex: (-0.25, 0.75)
Focus: (-0.25, 0.8125)
Directrix: y= -79