Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 1. In a class called H2P1, write a program (within main) that asks the u

ID: 3701733 • Letter: P

Question

Problem 1. In a class called H2P1, write a program (within main) that asks the user to enter the a, b, c values (separated by spaces and in this order) corresponding to the coefficients of a quadratic function in standard form: az2 +bx c. The program should then compute and output to the screen the r and y coordinates of the vertex of the parabola that represents the given quadratic function Furthermore, if the vertex is also a zero or a y-intercept (or both) for the same function, then you should print an appropriate message to the user indicating these facts. Here is a sample run of this program: Enter the a, b, and c of your quadratic function (separated by spaces): 1 0 0 The vertex of the corresponding parabola is: (0, 0) This vertex is also the zero of your parabola. This vertex is also the y-intercept of your parabola. Hint: For a function f(x)abx c, the vertex is at 2a2a

Explanation / Answer

import java.util.Scanner; public class Parabola { public static void main(String args[]) { final Scanner scanner = new Scanner(System.in); final double a = scanner.nextDouble(); final double b = scanner.nextDouble(); final double c = scanner.nextDouble(); final double vertexXcoordinate = calculateXcoordicateOfVertex(a, b); final double vertexYcoordinate = calculateYcoordicateOfVertex(a, b, c, vertexXcoordinate); System.out.println("The vertex of the corresponding parabola is (" + vertexXcoordinate + ", " + vertexYcoordinate + ")"); if (vertexXcoordinate == 0.0d) { System.out.println("The vertex is also the zero of your parabola"); } if (checkIfVertexIsYInterceptOfTheParabola(a, b, c, vertexXcoordinate, vertexYcoordinate)) { System.out.println("The vertex is also the y-intercept of your parabola"); } } private static double calculateXcoordicateOfVertex( final double a, final double b) { if (a == 0.0d) { throw new ArithmeticException("Divison By Zero"); } else { return -b / (2 * a); } } private static double calculateYcoordicateOfVertex( final double a, final double b, final double c, final double vertexXcoordinate) { return a*Math.pow(vertexXcoordinate, 2) + b*vertexXcoordinate + c; } private static boolean checkIfVertexIsYInterceptOfTheParabola( final double a, final double b, final double c, final double vertexXcoordinate, final double vertexYcoordinate) { final double discriminant = Math.sqrt(b*b - 4*a*c); final double valueXIntercept1 = (-b + discriminant) / (2*a); final double valueXIntercept2 = (-b - discriminant) / (2*a); return (Double.compare(vertexXcoordinate, valueXIntercept1) == 0) || (Double.compare(vertexXcoordinate, valueXIntercept2) == 0); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote